diff options
author | Takashi Iwai <tiwai@suse.de> | 2008-09-25 08:51:03 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2008-09-25 08:51:03 -0400 |
commit | 399ccdc1cd4e92e541d4dacbbf18c52bd693418b (patch) | |
tree | 4e9ecc896adb79397166c02bdd4cedd690a54a98 /sound | |
parent | b0b8daf7849cc98217ca018fbe82c61cd2b735bc (diff) |
ALSA: fix locking in snd_pcm_open*() and snd_rawmidi_open*()
The PCM and rawmidi open callbacks have a lock against card->controls_list
but it takes a wrong one, card->controls_rwsem, instead of a right one
card->ctl_files_rwlock. This patch fixes them.
This change also fixes automatically the potential deadlocks due to
mm->mmap_sem in munmap and copy_from/to_user, reported by Sitsofe
Wheeler:
A: snd_ctl_elem_user_tlv(): card->controls_rwsem => mm->mmap_sem
B: snd_pcm_open(): card->open_mutex => card->controls_rwsem
C: munmap: mm->mmap_sem => snd_pcm_release(): card->open_mutex
The patch breaks the chain.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound')
-rw-r--r-- | sound/core/pcm.c | 4 | ||||
-rw-r--r-- | sound/core/rawmidi.c | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/sound/core/pcm.c b/sound/core/pcm.c index 9dd9bc73fe1d..ece25c718e95 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c | |||
@@ -781,7 +781,7 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, | |||
781 | return -ENODEV; | 781 | return -ENODEV; |
782 | 782 | ||
783 | card = pcm->card; | 783 | card = pcm->card; |
784 | down_read(&card->controls_rwsem); | 784 | read_lock(&card->ctl_files_rwlock); |
785 | list_for_each_entry(kctl, &card->ctl_files, list) { | 785 | list_for_each_entry(kctl, &card->ctl_files, list) { |
786 | if (kctl->pid == current->pid) { | 786 | if (kctl->pid == current->pid) { |
787 | prefer_subdevice = kctl->prefer_pcm_subdevice; | 787 | prefer_subdevice = kctl->prefer_pcm_subdevice; |
@@ -789,7 +789,7 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, | |||
789 | break; | 789 | break; |
790 | } | 790 | } |
791 | } | 791 | } |
792 | up_read(&card->controls_rwsem); | 792 | read_unlock(&card->ctl_files_rwlock); |
793 | 793 | ||
794 | switch (stream) { | 794 | switch (stream) { |
795 | case SNDRV_PCM_STREAM_PLAYBACK: | 795 | case SNDRV_PCM_STREAM_PLAYBACK: |
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c index f7ea7287c59c..b917a9f981c7 100644 --- a/sound/core/rawmidi.c +++ b/sound/core/rawmidi.c | |||
@@ -418,7 +418,7 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file) | |||
418 | mutex_lock(&rmidi->open_mutex); | 418 | mutex_lock(&rmidi->open_mutex); |
419 | while (1) { | 419 | while (1) { |
420 | subdevice = -1; | 420 | subdevice = -1; |
421 | down_read(&card->controls_rwsem); | 421 | read_lock(&card->ctl_files_rwlock); |
422 | list_for_each_entry(kctl, &card->ctl_files, list) { | 422 | list_for_each_entry(kctl, &card->ctl_files, list) { |
423 | if (kctl->pid == current->pid) { | 423 | if (kctl->pid == current->pid) { |
424 | subdevice = kctl->prefer_rawmidi_subdevice; | 424 | subdevice = kctl->prefer_rawmidi_subdevice; |
@@ -426,7 +426,7 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file) | |||
426 | break; | 426 | break; |
427 | } | 427 | } |
428 | } | 428 | } |
429 | up_read(&card->controls_rwsem); | 429 | read_unlock(&card->ctl_files_rwlock); |
430 | err = snd_rawmidi_kernel_open(rmidi->card, rmidi->device, | 430 | err = snd_rawmidi_kernel_open(rmidi->card, rmidi->device, |
431 | subdevice, fflags, rawmidi_file); | 431 | subdevice, fflags, rawmidi_file); |
432 | if (err >= 0) | 432 | if (err >= 0) |