Blame SOURCES/CVE-2022-4378.patch

81ae6d
From 5b91e65d83213b25cc9529884a2106eee80c6c04 Mon Sep 17 00:00:00 2001
81ae6d
From: Ryan Sullivan <rysulliv@redhat.com>
81ae6d
Date: Thu, 26 Jan 2023 09:44:30 -0500
81ae6d
Subject: [KPATCH CVE-2022-4378] kpatch fixes for CVE-2022-4378
81ae6d
81ae6d
Kernels:
81ae6d
5.14.0-162.6.1.el9_1
81ae6d
5.14.0-162.12.1.el9_1
81ae6d
81ae6d
81ae6d
Kpatch-MR: https://gitlab.com/redhat/prdsc/rhel/src/kpatch/rhel-9/-/merge_requests/19
81ae6d
Approved-by: Joe Lawrence (@joe.lawrence)
81ae6d
Approved-by: Yannick Cote (@ycote1)
81ae6d
Changes since last build:
81ae6d
arches: x86_64 ppc64le
81ae6d
l2cap_core.o: changed function: l2cap_rx_state_recv
81ae6d
l2cap_core.o: changed function: l2cap_stream_rx
81ae6d
nfs4proc.o: changed function: nfsd4_copy
81ae6d
nfs4proc.o: changed function: nfsd4_do_async_copy
81ae6d
nft_payload.o: changed function: nft_payload_copy_vlan
81ae6d
sysctl.o: changed function: __do_proc_dointvec
81ae6d
sysctl.o: changed function: __do_proc_douintvec
81ae6d
sysctl.o: changed function: __do_proc_doulongvec_minmax
81ae6d
sysctl.o: changed function: proc_get_long.constprop.0
81ae6d
---------------------------
81ae6d
81ae6d
Modifications: none
81ae6d
81ae6d
commit d4c4d465e31fae6c3729b9c52a6bc3610494ead4
81ae6d
Author: Wander Lairson Costa <wander@redhat.com>
81ae6d
Date:   Mon Dec 12 15:30:46 2022 -0300
81ae6d
81ae6d
    proc: avoid integer type confusion in get_proc_long
81ae6d
81ae6d
    Bugzilla: https://bugzilla.redhat.com/2152580
81ae6d
    CVE: CVE-2022-4378
81ae6d
    Y-Commit: ab93541c2e72e570f9b6cf79ff943400961a30e1
81ae6d
81ae6d
    O-Bugzilla: https://bugzilla.redhat.com/2152581
81ae6d
    O-CVE: CVE-2022-4378
81ae6d
81ae6d
    commit e6cfaf34be9fcd1a8285a294e18986bfc41a409c
81ae6d
    Author: Linus Torvalds <torvalds@linux-foundation.org>
81ae6d
    Date:   Mon Dec 5 11:33:40 2022 -0800
81ae6d
81ae6d
        proc: avoid integer type confusion in get_proc_long
81ae6d
81ae6d
        proc_get_long() is passed a size_t, but then assigns it to an 'int'
81ae6d
        variable for the length.  Let's not do that, even if our IO paths are
81ae6d
        limited to MAX_RW_COUNT (exactly because of these kinds of type errors).
81ae6d
81ae6d
        So do the proper test in the rigth type.
81ae6d
81ae6d
        Reported-by: Kyle Zeng <zengyhkyle@gmail.com>
81ae6d
        Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
81ae6d
81ae6d
    Signed-off-by: Wander Lairson Costa <wander@redhat.com>
81ae6d
    Signed-off-by: Patrick Talbert <ptalbert@redhat.com>
81ae6d
81ae6d
commit 250391dd6ddc268d65901a1eaeb966a7256ef1cb
81ae6d
Author: Wander Lairson Costa <wander@redhat.com>
81ae6d
Date:   Mon Dec 12 15:30:50 2022 -0300
81ae6d
81ae6d
    proc: proc_skip_spaces() shouldn't think it is working on C strings
81ae6d
81ae6d
    Bugzilla: https://bugzilla.redhat.com/2152580
81ae6d
    CVE: CVE-2022-4378
81ae6d
    Y-Commit: a664fa0ecf20645f630e278b6da6aaabb3192954
81ae6d
81ae6d
    O-Bugzilla: https://bugzilla.redhat.com/2152581
81ae6d
    O-CVE: CVE-2022-4378
81ae6d
81ae6d
    commit bce9332220bd677d83b19d21502776ad555a0e73
81ae6d
    Author: Linus Torvalds <torvalds@linux-foundation.org>
81ae6d
    Date:   Mon Dec 5 12:09:06 2022 -0800
81ae6d
81ae6d
        proc: proc_skip_spaces() shouldn't think it is working on C strings
81ae6d
81ae6d
        proc_skip_spaces() seems to think it is working on C strings, and ends
81ae6d
        up being just a wrapper around skip_spaces() with a really odd calling
81ae6d
        convention.
81ae6d
81ae6d
        Instead of basing it on skip_spaces(), it should have looked more like
81ae6d
        proc_skip_char(), which really is the exact same function (except it
81ae6d
        skips a particular character, rather than whitespace).  So use that as
81ae6d
        inspiration, odd coding and all.
81ae6d
81ae6d
        Now the calling convention actually makes sense and works for the
81ae6d
        intended purpose.
81ae6d
81ae6d
        Reported-and-tested-by: Kyle Zeng <zengyhkyle@gmail.com>
81ae6d
        Acked-by: Eric Dumazet <edumazet@google.com>
81ae6d
        Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
81ae6d
81ae6d
    Signed-off-by: Wander Lairson Costa <wander@redhat.com>
81ae6d
    Signed-off-by: Patrick Talbert <ptalbert@redhat.com>
81ae6d
81ae6d
Signed-off-by: Ryan Sullivan <rysulliv@redhat.com>
81ae6d
---
81ae6d
 kernel/sysctl.c | 30 +++++++++++++++---------------
81ae6d
 1 file changed, 15 insertions(+), 15 deletions(-)
81ae6d
81ae6d
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
81ae6d
index 0dd902ee206e..e72cf05ca07b 100644
81ae6d
--- a/kernel/sysctl.c
81ae6d
+++ b/kernel/sysctl.c
81ae6d
@@ -391,13 +391,14 @@ int proc_dostring(struct ctl_table *table, int write,
81ae6d
 			ppos);
81ae6d
 }
81ae6d
 
81ae6d
-static size_t proc_skip_spaces(char **buf)
81ae6d
+static void proc_skip_spaces(char **buf, size_t *size)
81ae6d
 {
81ae6d
-	size_t ret;
81ae6d
-	char *tmp = skip_spaces(*buf);
81ae6d
-	ret = tmp - *buf;
81ae6d
-	*buf = tmp;
81ae6d
-	return ret;
81ae6d
+	while (*size) {
81ae6d
+		if (!isspace(**buf))
81ae6d
+			break;
81ae6d
+		(*size)--;
81ae6d
+		(*buf)++;
81ae6d
+	}
81ae6d
 }
81ae6d
 
81ae6d
 static void proc_skip_char(char **buf, size_t *size, const char v)
81ae6d
@@ -466,13 +467,12 @@ static int proc_get_long(char **buf, size_t *size,
81ae6d
 			  unsigned long *val, bool *neg,
81ae6d
 			  const char *perm_tr, unsigned perm_tr_len, char *tr)
81ae6d
 {
81ae6d
-	int len;
81ae6d
 	char *p, tmp[TMPBUFLEN];
81ae6d
+	ssize_t len = *size;
81ae6d
 
81ae6d
-	if (!*size)
81ae6d
+	if (len <= 0)
81ae6d
 		return -EINVAL;
81ae6d
 
81ae6d
-	len = *size;
81ae6d
 	if (len > TMPBUFLEN - 1)
81ae6d
 		len = TMPBUFLEN - 1;
81ae6d
 
81ae6d
@@ -645,7 +645,7 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
81ae6d
 		bool neg;
81ae6d
 
81ae6d
 		if (write) {
81ae6d
-			left -= proc_skip_spaces(&p);
81ae6d
+			proc_skip_spaces(&p, &left);
81ae6d
 
81ae6d
 			if (!left)
81ae6d
 				break;
81ae6d
@@ -672,7 +672,7 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
81ae6d
 	if (!write && !first && left && !err)
81ae6d
 		proc_put_char(&buffer, &left, '\n');
81ae6d
 	if (write && !err && left)
81ae6d
-		left -= proc_skip_spaces(&p);
81ae6d
+		proc_skip_spaces(&p, &left);
81ae6d
 	if (write && first)
81ae6d
 		return err ? : -EINVAL;
81ae6d
 	*lenp -= left;
81ae6d
@@ -714,7 +714,7 @@ static int do_proc_douintvec_w(unsigned int *tbl_data,
81ae6d
 	if (left > PAGE_SIZE - 1)
81ae6d
 		left = PAGE_SIZE - 1;
81ae6d
 
81ae6d
-	left -= proc_skip_spaces(&p);
81ae6d
+	proc_skip_spaces(&p, &left);
81ae6d
 	if (!left) {
81ae6d
 		err = -EINVAL;
81ae6d
 		goto out_free;
81ae6d
@@ -734,7 +734,7 @@ static int do_proc_douintvec_w(unsigned int *tbl_data,
81ae6d
 	}
81ae6d
 
81ae6d
 	if (!err && left)
81ae6d
-		left -= proc_skip_spaces(&p);
81ae6d
+		proc_skip_spaces(&p, &left);
81ae6d
 
81ae6d
 out_free:
81ae6d
 	if (err)
81ae6d
@@ -1271,7 +1271,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
81ae6d
 		if (write) {
81ae6d
 			bool neg;
81ae6d
 
81ae6d
-			left -= proc_skip_spaces(&p);
81ae6d
+			proc_skip_spaces(&p, &left);
81ae6d
 			if (!left)
81ae6d
 				break;
81ae6d
 
81ae6d
@@ -1299,7 +1299,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
81ae6d
 	if (!write && !first && left && !err)
81ae6d
 		proc_put_char(&buffer, &left, '\n');
81ae6d
 	if (write && !err)
81ae6d
-		left -= proc_skip_spaces(&p);
81ae6d
+		proc_skip_spaces(&p, &left);
81ae6d
 	if (write && first)
81ae6d
 		return err ? : -EINVAL;
81ae6d
 	*lenp -= left;
81ae6d
-- 
81ae6d
2.39.1
81ae6d
81ae6d