Blame SOURCES/CVE-2022-4378.patch

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