From c88c22f99e57a24c6738e08d01c782162947ff5d Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 13 Jan 2023 16:49:43 +0100 Subject: [PATCH] 4.19-stable patches added patches: alsa-pcm-move-rwsem-lock-inside-snd_ctl_elem_read-to-prevent-uaf.patch --- ...ide-snd_ctl_elem_read-to-prevent-uaf.patch | 64 +++++++++++++++++++ queue-4.19/series | 1 + 2 files changed, 65 insertions(+) create mode 100644 queue-4.19/alsa-pcm-move-rwsem-lock-inside-snd_ctl_elem_read-to-prevent-uaf.patch diff --git a/queue-4.19/alsa-pcm-move-rwsem-lock-inside-snd_ctl_elem_read-to-prevent-uaf.patch b/queue-4.19/alsa-pcm-move-rwsem-lock-inside-snd_ctl_elem_read-to-prevent-uaf.patch new file mode 100644 index 00000000000..27d472162e8 --- /dev/null +++ b/queue-4.19/alsa-pcm-move-rwsem-lock-inside-snd_ctl_elem_read-to-prevent-uaf.patch @@ -0,0 +1,64 @@ +From 56b88b50565cd8b946a2d00b0c83927b7ebb055e Mon Sep 17 00:00:00 2001 +From: Clement Lecigne +Date: Fri, 13 Jan 2023 13:07:45 +0100 +Subject: ALSA: pcm: Move rwsem lock inside snd_ctl_elem_read to prevent UAF + +From: Clement Lecigne + +[ 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. + +Signed-off-by: Clement Lecigne +Cc: stable@kernel.org # 5.12 and older +Signed-off-by: Takashi Iwai +Reviewed-by: Jaroslav Kysela +Signed-off-by: Greg Kroah-Hartman +--- + sound/core/control_compat.c | 4 ++++ + 1 file changed, 4 insertions(+) + +--- a/sound/core/control_compat.c ++++ b/sound/core/control_compat.c +@@ -319,7 +319,9 @@ static int ctl_elem_read_user(struct snd + err = snd_power_wait(card, SNDRV_CTL_POWER_D0); + if (err < 0) + goto error; ++ down_read(&card->controls_rwsem); + err = snd_ctl_elem_read(card, data); ++ up_read(&card->controls_rwsem); + if (err < 0) + goto error; + err = copy_ctl_value_to_user(userdata, valuep, data, type, count); +@@ -347,7 +349,9 @@ static int ctl_elem_write_user(struct sn + err = snd_power_wait(card, SNDRV_CTL_POWER_D0); + if (err < 0) + goto error; ++ down_write(&card->controls_rwsem); + err = snd_ctl_elem_write(card, file, data); ++ up_write(&card->controls_rwsem); + if (err < 0) + goto error; + err = copy_ctl_value_to_user(userdata, valuep, data, type, count); diff --git a/queue-4.19/series b/queue-4.19/series index f5669eff009..553521d4959 100644 --- a/queue-4.19/series +++ b/queue-4.19/series @@ -464,3 +464,4 @@ parisc-align-parisc-madv_xxx-constants-with-all-other-architectures.patch driver-core-fix-bus_type.match-error-handling-in-__driver_attach.patch net-sched-disallow-noqueue-for-qdisc-classes.patch net-ulp-prevent-ulp-without-clone-op-from-entering-the-listen-status.patch +alsa-pcm-move-rwsem-lock-inside-snd_ctl_elem_read-to-prevent-uaf.patch -- 2.47.3