Blame SOURCES/CVE-2023-0266.patch

497ac3
From 120548cde1d7642ff79d71827993e32babfb4e2f Mon Sep 17 00:00:00 2001
497ac3
From: Ryan Sullivan <rysulliv@redhat.com>
497ac3
Date: Fri, 17 Feb 2023 12:26:57 -0500
497ac3
Subject: [KPATCH CVE-2023-0266] kpatch fixes for CVE-2023-0266
497ac3
497ac3
Kernels:
497ac3
5.14.0-162.6.1.el9_1
497ac3
5.14.0-162.12.1.el9_1
497ac3
497ac3
497ac3
Kpatch-MR: https://gitlab.com/redhat/prdsc/rhel/src/kpatch/rhel-9/-/merge_requests/24
497ac3
Approved-by: Yannick Cote (@ycote1)
497ac3
Approved-by: Joe Lawrence (@joe.lawrence)
497ac3
Changes since last build:
497ac3
[x86_64]:
497ac3
control.o: changed function: snd_ctl_elem_read
497ac3
control.o: changed function: snd_ctl_ioctl
497ac3
dev.o: changed function: register_netdevice
497ac3
tun.o: changed function: tun_free_netdev
497ac3
tun.o: changed function: tun_set_iff.constprop.0
497ac3
tun.o: new function: kpp_cve_2022_4744_tun_net_init
497ac3
497ac3
[ppc64le]:
497ac3
dev.o: changed function: register_netdevice
497ac3
tun.o: changed function: tun_free_netdev
497ac3
tun.o: changed function: tun_set_iff.constprop.0
497ac3
tun.o: new function: kpp_cve_2022_4744_tun_net_init
497ac3
497ac3
---------------------------
497ac3
497ac3
Modifications: none
497ac3
497ac3
commit c0295d3bd6b49f47e30822a9de9c042020092424
497ac3
Author: Jaroslav Kysela <jkysela@redhat.com>
497ac3
Date:   Tue Jan 31 17:13:11 2023 +0100
497ac3
497ac3
    ALSA: pcm: Move rwsem lock inside snd_ctl_elem_read to prevent UAF
497ac3
497ac3
    Takes rwsem lock inside snd_ctl_elem_read instead of snd_ctl_elem_read_user
497ac3
    like it was done for write in commit 1fa4445f9adf1 ("ALSA: control - introduce
497ac3
    snd_ctl_notify_one() helper"). Doing this way we are also fixing the following
497ac3
    locking issue happening in the compat path which can be easily triggered and
497ac3
    turned into an use-after-free.
497ac3
497ac3
    64-bits:
497ac3
    snd_ctl_ioctl
497ac3
      snd_ctl_elem_read_user
497ac3
        [takes controls_rwsem]
497ac3
        snd_ctl_elem_read [lock properly held, all good]
497ac3
        [drops controls_rwsem]
497ac3
497ac3
    32-bits:
497ac3
    snd_ctl_ioctl_compat
497ac3
      snd_ctl_elem_write_read_compat
497ac3
        ctl_elem_write_read
497ac3
          snd_ctl_elem_read [missing lock, not good]
497ac3
497ac3
    CVE-2023-0266 was assigned for this issue.
497ac3
497ac3
        Cc: stable@kernel.org # 5.13+
497ac3
        Signed-off-by: Clement Lecigne <clecigne@google.com>
497ac3
        Reviewed-by: Jaroslav Kysela <perex@perex.cz>
497ac3
        Link: https://lore.kernel.org/r/20230113120745.25464-1-tiwai@suse.de
497ac3
        Signed-off-by: Takashi Iwai <tiwai@suse.de>
497ac3
497ac3
    Author: Clement Lecigne <clecigne@google.com>
497ac3
    Date: Fri Jan 13 13:07:45 2023 +0100
497ac3
497ac3
    CVE: CVE-2023-0266
497ac3
497ac3
    Signed-off-by: Jaroslav Kysela <jkysela@redhat.com>
497ac3
    (cherry picked from commit 56b88b50565cd8b946a2d00b0c83927b7ebb055e)
497ac3
    Bugzilla: https://bugzilla.redhat.com/2163390
497ac3
497ac3
Signed-off-by: Ryan Sullivan <rysulliv@redhat.com>
497ac3
---
497ac3
 sound/core/control.c | 24 +++++++++++++++---------
497ac3
 1 file changed, 15 insertions(+), 9 deletions(-)
497ac3
497ac3
diff --git a/sound/core/control.c b/sound/core/control.c
497ac3
index a25c0d64d104..6e2a1e424627 100644
497ac3
--- a/sound/core/control.c
497ac3
+++ b/sound/core/control.c
497ac3
@@ -1066,14 +1066,19 @@ static int snd_ctl_elem_read(struct snd_card *card,
497ac3
 	const u32 pattern = 0xdeadbeef;
497ac3
 	int ret;
497ac3
 
497ac3
+	down_read(&card->controls_rwsem);
497ac3
 	kctl = snd_ctl_find_id(card, &control->id);
497ac3
-	if (kctl == NULL)
497ac3
-		return -ENOENT;
497ac3
+	if (kctl == NULL) {
497ac3
+		ret = -ENOENT;
497ac3
+		goto unlock;
497ac3
+	}
497ac3
 
497ac3
 	index_offset = snd_ctl_get_ioff(kctl, &control->id);
497ac3
 	vd = &kctl->vd[index_offset];
497ac3
-	if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_READ) || kctl->get == NULL)
497ac3
-		return -EPERM;
497ac3
+	if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_READ) || kctl->get == NULL) {
497ac3
+		ret = -EPERM;
497ac3
+		goto unlock;
497ac3
+	}
497ac3
 
497ac3
 	snd_ctl_build_ioff(&control->id, kctl, index_offset);
497ac3
 
497ac3
@@ -1083,7 +1088,7 @@ static int snd_ctl_elem_read(struct snd_card *card,
497ac3
 	info.id = control->id;
497ac3
 	ret = __snd_ctl_elem_info(card, kctl, &info, NULL);
497ac3
 	if (ret < 0)
497ac3
-		return ret;
497ac3
+		goto unlock;
497ac3
 #endif
497ac3
 
497ac3
 	if (!snd_ctl_skip_validation(&info))
497ac3
@@ -1093,7 +1098,7 @@ static int snd_ctl_elem_read(struct snd_card *card,
497ac3
 		ret = kctl->get(kctl, control);
497ac3
 	snd_power_unref(card);
497ac3
 	if (ret < 0)
497ac3
-		return ret;
497ac3
+		goto unlock;
497ac3
 	if (!snd_ctl_skip_validation(&info) &&
497ac3
 	    sanity_check_elem_value(card, control, &info, pattern) < 0) {
497ac3
 		dev_err(card->dev,
497ac3
@@ -1101,8 +1106,11 @@ static int snd_ctl_elem_read(struct snd_card *card,
497ac3
 			control->id.iface, control->id.device,
497ac3
 			control->id.subdevice, control->id.name,
497ac3
 			control->id.index);
497ac3
-		return -EINVAL;
497ac3
+		ret = -EINVAL;
497ac3
+		goto unlock;
497ac3
 	}
497ac3
+unlock:
497ac3
+	up_read(&card->controls_rwsem);
497ac3
 	return ret;
497ac3
 }
497ac3
 
497ac3
@@ -1116,9 +1124,7 @@ static int snd_ctl_elem_read_user(struct snd_card *card,
497ac3
 	if (IS_ERR(control))
497ac3
 		return PTR_ERR(control);
497ac3
 
497ac3
-	down_read(&card->controls_rwsem);
497ac3
 	result = snd_ctl_elem_read(card, control);
497ac3
-	up_read(&card->controls_rwsem);
497ac3
 	if (result < 0)
497ac3
 		goto error;
497ac3
 
497ac3
-- 
497ac3
2.39.2
497ac3
497ac3