Skip to content

Commit

Permalink
ALSA: firewire-motu: fix null pointer dereference when polling hwdep …
Browse files Browse the repository at this point in the history
…character device

ALSA firewire-motu driver recently got support for event notification via
ALSA HwDep interface for register DSP models. However, when polling ALSA
HwDep cdev, the driver can cause null pointer dereference for the other
models due to accessing to unallocated memory or uninitialized memory.

This commit fixes the bug by check the type of model before accessing to
the memory.

Reported-by: kernel test robot <[email protected]>
Suggested-by: Takashi Iwai <[email protected]>
Fixes: 634ec0b ("ALSA: firewire-motu: notify event for parameter change in register DSP model")
Signed-off-by: Takashi Sakamoto <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
takaswie authored and tiwai committed Oct 28, 2021
1 parent 375f842 commit d593f78
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions sound/firewire/motu/motu-hwdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@

#include "motu.h"

static bool has_dsp_event(struct snd_motu *motu)
{
if (motu->spec->flags & SND_MOTU_SPEC_REGISTER_DSP)
return (snd_motu_register_dsp_message_parser_count_event(motu) > 0);
else
return false;
}

static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,
loff_t *offset)
{
Expand All @@ -25,8 +33,7 @@ static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,

spin_lock_irq(&motu->lock);

while (!motu->dev_lock_changed && motu->msg == 0 &&
snd_motu_register_dsp_message_parser_count_event(motu) == 0) {
while (!motu->dev_lock_changed && motu->msg == 0 && !has_dsp_event(motu)) {
prepare_to_wait(&motu->hwdep_wait, &wait, TASK_INTERRUPTIBLE);
spin_unlock_irq(&motu->lock);
schedule();
Expand Down Expand Up @@ -55,7 +62,7 @@ static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,
count = min_t(long, count, sizeof(event));
if (copy_to_user(buf, &event, count))
return -EFAULT;
} else if (snd_motu_register_dsp_message_parser_count_event(motu) > 0) {
} else if (has_dsp_event(motu)) {
size_t consumed = 0;
u32 __user *ptr;
u32 ev;
Expand Down Expand Up @@ -94,8 +101,7 @@ static __poll_t hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
poll_wait(file, &motu->hwdep_wait, wait);

spin_lock_irq(&motu->lock);
if (motu->dev_lock_changed || motu->msg ||
snd_motu_register_dsp_message_parser_count_event(motu) > 0)
if (motu->dev_lock_changed || motu->msg || has_dsp_event(motu))
events = EPOLLIN | EPOLLRDNORM;
else
events = 0;
Expand Down

0 comments on commit d593f78

Please sign in to comment.