Skip to content

Commit 7094a28

Browse files
Clement LecignemikeNG
authored andcommitted
ALSA: pcm: Move rwsem lock inside snd_ctl_elem_read to prevent UAF
[ Note: this is a fix that works around the bug equivalently as the two upstream commits: 1fa4445f9adf ("ALSA: control - introduce snd_ctl_notify_one() helper") 56b88b50565c ("ALSA: pcm: Move rwsem lock inside snd_ctl_elem_read to prevent UAF") but in a simpler way to fit with older stable trees -- tiwai ] Add missing locking in ctl_elem_read_user/ctl_elem_write_user which can be easily triggered and turned into an use-after-free. Example code paths with SNDRV_CTL_IOCTL_ELEM_READ: 64-bits: snd_ctl_ioctl snd_ctl_elem_read_user [takes controls_rwsem] snd_ctl_elem_read [lock properly held, all good] [drops controls_rwsem] 32-bits (compat): snd_ctl_ioctl_compat snd_ctl_elem_write_read_compat ctl_elem_write_read snd_ctl_elem_read [missing lock, not good] CVE-2023-0266 was assigned for this issue. Bug: 265303544 Signed-off-by: Clement Lecigne <clecigne@google.com> Cc: stable@vger.kernel.org # 5.12 and older Signed-off-by: Takashi Iwai <tiwai@suse.de> Reviewed-by: Jaroslav Kysela <perex@perex.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Change-Id: I09e6834ccdacb1e35b4dfa20d94e82a0e4afac7e
1 parent b0bd316 commit 7094a28

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

sound/core/control_compat.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,11 @@ static int ctl_elem_read_user(struct snd_card *card,
320320

321321
snd_power_lock(card);
322322
err = snd_power_wait(card, SNDRV_CTL_POWER_D0);
323-
if (err >= 0)
323+
if (err >= 0) {
324+
down_read(&card->controls_rwsem);
324325
err = snd_ctl_elem_read(card, data);
326+
up_read(&card->controls_rwsem);
327+
}
325328
snd_power_unlock(card);
326329
if (err >= 0)
327330
err = copy_ctl_value_to_user(userdata, valuep, data,
@@ -349,8 +352,11 @@ static int ctl_elem_write_user(struct snd_ctl_file *file,
349352

350353
snd_power_lock(card);
351354
err = snd_power_wait(card, SNDRV_CTL_POWER_D0);
352-
if (err >= 0)
355+
if (err >= 0) {
356+
down_write(&card->controls_rwsem);
353357
err = snd_ctl_elem_write(card, file, data);
358+
up_write(&card->controls_rwsem);
359+
}
354360
snd_power_unlock(card);
355361
if (err >= 0)
356362
err = copy_ctl_value_to_user(userdata, valuep, data,

0 commit comments

Comments
 (0)