Blame SOURCES/CVE-2022-4378.patch

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