Skip to content

Commit

Permalink
ALSA: firewire-tascam: accessing to user space outside spinlock
Browse files Browse the repository at this point in the history
In hwdep interface of firewire-tascam driver, accessing to user space is
in a critical section with disabled local interrupt. Depending on
architecture, accessing to user space can cause page fault exception. Then
local processor stores machine status and handle the synchronous event. A
handler corresponding to the event can call task scheduler to wait for
preparing pages. In a case of usage of single core processor, the state to
disable local interrupt is worse because it doesn't handle usual interrupts
from hardware.

This commit fixes this bug, by performing the accessing outside spinlock.

Reported-by: Vaishali Thakkar <vaishali.thakkar@oracle.com>
Cc: stable@vger.kernel.org
Fixes: e5e0c3d('ALSA: firewire-tascam: add hwdep interface')
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
Takashi Sakamoto authored and Takashi Iwai committed Aug 31, 2016
1 parent fd06c77 commit 04b2d9c
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions sound/firewire/tascam/tascam-hwdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,14 @@

#include "tascam.h"

static long hwdep_read_locked(struct snd_tscm *tscm, char __user *buf,
long count)
{
union snd_firewire_event event;

memset(&event, 0, sizeof(event));

event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS;
event.lock_status.status = (tscm->dev_lock_count > 0);
tscm->dev_lock_changed = false;

count = min_t(long, count, sizeof(event.lock_status));

if (copy_to_user(buf, &event, count))
return -EFAULT;

return count;
}

static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,
loff_t *offset)
{
struct snd_tscm *tscm = hwdep->private_data;
DEFINE_WAIT(wait);
union snd_firewire_event event;
union snd_firewire_event event = {
.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS,
};

spin_lock_irq(&tscm->lock);

Expand All @@ -54,10 +37,16 @@ static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,
spin_lock_irq(&tscm->lock);
}

memset(&event, 0, sizeof(event));
count = hwdep_read_locked(tscm, buf, count);
event.lock_status.status = (tscm->dev_lock_count > 0);
tscm->dev_lock_changed = false;

spin_unlock_irq(&tscm->lock);

count = min_t(long, count, sizeof(event.lock_status));

if (copy_to_user(buf, &event, count))
return -EFAULT;

return count;
}

Expand Down

0 comments on commit 04b2d9c

Please sign in to comment.