Blame SOURCES/CVE-2022-4378.patch

cc0e73
From daf9de90e88ffb2e303145733167327f92b869c2 Mon Sep 17 00:00:00 2001
cc0e73
From: Ryan Sullivan <rysulliv@redhat.com>
cc0e73
Date: Tue, 7 Feb 2023 12:08:05 -0500
cc0e73
Subject: [KPATCH CVE-2022-4378] kpatch fixes for CVE-2022-4378
cc0e73
cc0e73
Kernels:
cc0e73
4.18.0-425.3.1.el8
cc0e73
4.18.0-425.10.1.el8_7
cc0e73
cc0e73
cc0e73
Kpatch-MR: https://gitlab.com/redhat/prdsc/rhel/src/kpatch/rhel-8/-/merge_requests/82
cc0e73
Approved-by: Joe Lawrence (@joe.lawrence)
cc0e73
Approved-by: Yannick Cote (@ycote1)
cc0e73
Changes since last build:
cc0e73
[x86_64]:
cc0e73
control.o: changed function: snd_ctl_elem_read
cc0e73
control.o: changed function: snd_ctl_ioctl
cc0e73
sysctl.o: changed function: __do_proc_dointvec
cc0e73
sysctl.o: changed function: __do_proc_douintvec
cc0e73
sysctl.o: changed function: __do_proc_doulongvec_minmax
cc0e73
sysctl.o: changed function: proc_get_long.constprop.14
cc0e73
cc0e73
[ppc64le]:
cc0e73
control.o: changed function: snd_ctl_elem_read
cc0e73
control.o: changed function: snd_ctl_ioctl
cc0e73
sysctl.o: changed function: __do_proc_dointvec
cc0e73
sysctl.o: changed function: __do_proc_doulongvec_minmax
cc0e73
sysctl.o: changed function: proc_dopipe_max_size
cc0e73
sysctl.o: changed function: proc_douintvec
cc0e73
sysctl.o: changed function: proc_douintvec_minmax
cc0e73
sysctl.o: changed function: proc_get_long.constprop.14
cc0e73
cc0e73
---------------------------
cc0e73
cc0e73
Modifications: none
cc0e73
cc0e73
commit 8c873c04cfd546b8b29ae86dc35414cf4167d163
cc0e73
Author: Wander Lairson Costa <wander@redhat.com>
cc0e73
Date:   Mon Dec 12 15:43:15 2022 -0300
cc0e73
cc0e73
    proc: avoid integer type confusion in get_proc_long
cc0e73
cc0e73
    Bugzilla: https://bugzilla.redhat.com/2152571
cc0e73
    CVE: CVE-2022-4378
cc0e73
    Y-Commit: bbda4302821f46972d5139f9af87993a7a07306e
cc0e73
cc0e73
    O-Bugzilla: https://bugzilla.redhat.com/2152572
cc0e73
    O-CVE: CVE-2022-4378
cc0e73
cc0e73
    commit e6cfaf34be9fcd1a8285a294e18986bfc41a409c
cc0e73
    Author: Linus Torvalds <torvalds@linux-foundation.org>
cc0e73
    Date:   Mon Dec 5 11:33:40 2022 -0800
cc0e73
cc0e73
        proc: avoid integer type confusion in get_proc_long
cc0e73
cc0e73
        proc_get_long() is passed a size_t, but then assigns it to an 'int'
cc0e73
        variable for the length.  Let's not do that, even if our IO paths are
cc0e73
        limited to MAX_RW_COUNT (exactly because of these kinds of type errors).
cc0e73
cc0e73
        So do the proper test in the rigth type.
cc0e73
cc0e73
        Reported-by: Kyle Zeng <zengyhkyle@gmail.com>
cc0e73
        Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
cc0e73
cc0e73
    Signed-off-by: Wander Lairson Costa <wander@redhat.com>
cc0e73
    Signed-off-by: Jarod Wilson <jarod@redhat.com>
cc0e73
cc0e73
commit 2347e6da850ca59e4730578b53d0e9339a1bb1e6
cc0e73
Author: Wander Lairson Costa <wander@redhat.com>
cc0e73
Date:   Mon Dec 12 15:47:25 2022 -0300
cc0e73
cc0e73
    proc: proc_skip_spaces() shouldn't think it is working on C strings
cc0e73
cc0e73
    Bugzilla: https://bugzilla.redhat.com/2152571
cc0e73
    CVE: CVE-2022-4378
cc0e73
    Y-Commit: ec2f9f80ba44b533578349a97fb2fe9894142221
cc0e73
cc0e73
    O-Bugzilla: https://bugzilla.redhat.com/2152572
cc0e73
    O-CVE: CVE-2022-4378
cc0e73
cc0e73
    Conflicts: context hunks because out version is much older than
cc0e73
               upstream.
cc0e73
cc0e73
    commit bce9332220bd677d83b19d21502776ad555a0e73
cc0e73
    Author: Linus Torvalds <torvalds@linux-foundation.org>
cc0e73
    Date:   Mon Dec 5 12:09:06 2022 -0800
cc0e73
cc0e73
        proc: proc_skip_spaces() shouldn't think it is working on C strings
cc0e73
cc0e73
        proc_skip_spaces() seems to think it is working on C strings, and ends
cc0e73
        up being just a wrapper around skip_spaces() with a really odd calling
cc0e73
        convention.
cc0e73
cc0e73
        Instead of basing it on skip_spaces(), it should have looked more like
cc0e73
        proc_skip_char(), which really is the exact same function (except it
cc0e73
        skips a particular character, rather than whitespace).  So use that as
cc0e73
        inspiration, odd coding and all.
cc0e73
cc0e73
        Now the calling convention actually makes sense and works for the
cc0e73
        intended purpose.
cc0e73
cc0e73
        Reported-and-tested-by: Kyle Zeng <zengyhkyle@gmail.com>
cc0e73
        Acked-by: Eric Dumazet <edumazet@google.com>
cc0e73
        Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
cc0e73
cc0e73
    Signed-off-by: Wander Lairson Costa <wander@redhat.com>
cc0e73
    Signed-off-by: Jarod Wilson <jarod@redhat.com>
cc0e73
cc0e73
Signed-off-by: Ryan Sullivan <rysulliv@redhat.com>
cc0e73
---
cc0e73
 kernel/sysctl.c | 30 +++++++++++++++---------------
cc0e73
 1 file changed, 15 insertions(+), 15 deletions(-)
cc0e73
cc0e73
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
cc0e73
index b4c8a670e9e0..3c8a3a787528 100644
cc0e73
--- a/kernel/sysctl.c
cc0e73
+++ b/kernel/sysctl.c
cc0e73
@@ -2194,13 +2194,14 @@ int proc_dostring(struct ctl_table *table, int write,
cc0e73
 			       (char __user *)buffer, lenp, ppos);
cc0e73
 }
cc0e73
 
cc0e73
-static size_t proc_skip_spaces(char **buf)
cc0e73
+static void proc_skip_spaces(char **buf, size_t *size)
cc0e73
 {
cc0e73
-	size_t ret;
cc0e73
-	char *tmp = skip_spaces(*buf);
cc0e73
-	ret = tmp - *buf;
cc0e73
-	*buf = tmp;
cc0e73
-	return ret;
cc0e73
+	while (*size) {
cc0e73
+		if (!isspace(**buf))
cc0e73
+			break;
cc0e73
+		(*size)--;
cc0e73
+		(*buf)++;
cc0e73
+	}
cc0e73
 }
cc0e73
 
cc0e73
 static void proc_skip_char(char **buf, size_t *size, const char v)
cc0e73
@@ -2269,13 +2270,12 @@ static int proc_get_long(char **buf, size_t *size,
cc0e73
 			  unsigned long *val, bool *neg,
cc0e73
 			  const char *perm_tr, unsigned perm_tr_len, char *tr)
cc0e73
 {
cc0e73
-	int len;
cc0e73
 	char *p, tmp[TMPBUFLEN];
cc0e73
+	ssize_t len = *size;
cc0e73
 
cc0e73
-	if (!*size)
cc0e73
+	if (len <= 0)
cc0e73
 		return -EINVAL;
cc0e73
 
cc0e73
-	len = *size;
cc0e73
 	if (len > TMPBUFLEN - 1)
cc0e73
 		len = TMPBUFLEN - 1;
cc0e73
 
cc0e73
@@ -2438,7 +2438,7 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
cc0e73
 		bool neg;
cc0e73
 
cc0e73
 		if (write) {
cc0e73
-			left -= proc_skip_spaces(&p);
cc0e73
+			proc_skip_spaces(&p, &left);
cc0e73
 
cc0e73
 			if (!left)
cc0e73
 				break;
cc0e73
@@ -2469,7 +2469,7 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
cc0e73
 	if (!write && !first && left && !err)
cc0e73
 		err = proc_put_char(&buffer, &left, '\n');
cc0e73
 	if (write && !err && left)
cc0e73
-		left -= proc_skip_spaces(&p);
cc0e73
+		proc_skip_spaces(&p, &left);
cc0e73
 	if (write) {
cc0e73
 		kfree(kbuf);
cc0e73
 		if (first)
cc0e73
@@ -2518,7 +2518,7 @@ static int do_proc_douintvec_w(unsigned int *tbl_data,
cc0e73
 	if (IS_ERR(kbuf))
cc0e73
 		return -EINVAL;
cc0e73
 
cc0e73
-	left -= proc_skip_spaces(&p);
cc0e73
+	proc_skip_spaces(&p, &left);
cc0e73
 	if (!left) {
cc0e73
 		err = -EINVAL;
cc0e73
 		goto out_free;
cc0e73
@@ -2538,7 +2538,7 @@ static int do_proc_douintvec_w(unsigned int *tbl_data,
cc0e73
 	}
cc0e73
 
cc0e73
 	if (!err && left)
cc0e73
-		left -= proc_skip_spaces(&p);
cc0e73
+		proc_skip_spaces(&p, &left);
cc0e73
 
cc0e73
 out_free:
cc0e73
 	kfree(kbuf);
cc0e73
@@ -2982,7 +2982,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
cc0e73
 		if (write) {
cc0e73
 			bool neg;
cc0e73
 
cc0e73
-			left -= proc_skip_spaces(&p);
cc0e73
+			proc_skip_spaces(&p, &left);
cc0e73
 
cc0e73
 			err = proc_get_long(&p, &left, &val, &neg,
cc0e73
 					     proc_wspace_sep,
cc0e73
@@ -3013,7 +3013,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
cc0e73
 	if (!write && !first && left && !err)
cc0e73
 		err = proc_put_char(&buffer, &left, '\n');
cc0e73
 	if (write && !err)
cc0e73
-		left -= proc_skip_spaces(&p);
cc0e73
+		proc_skip_spaces(&p, &left);
cc0e73
 	if (write) {
cc0e73
 		kfree(kbuf);
cc0e73
 		if (first)
cc0e73
-- 
cc0e73
2.39.2
cc0e73
cc0e73