Blame SOURCES/CVE-2022-4378.patch

82094d
From 794229b5711a96a488d85dd719511a278b4a4956 Mon Sep 17 00:00:00 2001
82094d
From: Ryan Sullivan <rysulliv@redhat.com>
82094d
Date: Fri, 27 Jan 2023 11:25:43 -0500
82094d
Subject: [KPATCH CVE-2022-4378] kpatch fixes for CVE-2022-4378
82094d
82094d
82094d
Kpatch-MR: https://gitlab.com/redhat/prdsc/rhel/src/kpatch/rhel-7/-/merge_requests/51
82094d
Approved-by: Yannick Cote (@ycote1)
82094d
Approved-by: Joe Lawrence (@joe.lawrence)
82094d
Kernels:
82094d
3.10.0-1160.76.1.el7
82094d
3.10.0-1160.80.1.el7
82094d
3.10.0-1160.81.1.el7
82094d
3.10.0-1160.83.1.el7
82094d
82094d
Changes since last build:
82094d
[x86_64]:
82094d
sysctl.o: changed function: __do_proc_dointvec
82094d
sysctl.o: changed function: __do_proc_douintvec
82094d
sysctl.o: changed function: __do_proc_doulongvec_minmax
82094d
sysctl.o: changed function: proc_dostring
82094d
sysctl.o: changed function: proc_get_long.constprop.13
82094d
82094d
[ppc64le]:
82094d
sysctl.o: changed function: __do_proc_doulongvec_minmax
82094d
sysctl.o: changed function: proc_do_cad_pid
82094d
sysctl.o: changed function: proc_dointvec
82094d
sysctl.o: changed function: proc_dointvec_jiffies
82094d
sysctl.o: changed function: proc_dointvec_minmax
82094d
sysctl.o: changed function: proc_dointvec_minmax_coredump
82094d
sysctl.o: changed function: proc_dointvec_minmax_sysadmin
82094d
sysctl.o: changed function: proc_dointvec_ms_jiffies
82094d
sysctl.o: changed function: proc_dointvec_userhz_jiffies
82094d
sysctl.o: changed function: proc_dopipe_max_size
82094d
sysctl.o: changed function: proc_dostring
82094d
sysctl.o: changed function: proc_dostring_coredump
82094d
sysctl.o: changed function: proc_douintvec
82094d
sysctl.o: changed function: proc_douintvec_minmax
82094d
sysctl.o: changed function: proc_doulongvec_minmax
82094d
sysctl.o: changed function: proc_doulongvec_ms_jiffies_minmax
82094d
sysctl.o: changed function: proc_get_long.constprop.13
82094d
sysctl.o: changed function: sysrq_sysctl_handler
82094d
sysctl.o: new function: __do_proc_dointvec
82094d
82094d
---------------------------
82094d
82094d
Modifications:
82094d
added '__attribute__((optimize("-fno-optimize-sibling-calls")))' to
82094d
proc_dointvec_jiffies(), proc_dointvec_ms_jiffies(), proc_doulongvec_ms_jiffies_minmax(),
82094d
proc_doulongvec_minmax(), proc_dointvec_userhz_jiffies(), and proc_dointvec() definitions.
82094d
82094d
commit f4f6d6bf0cd6fc3d1b88341f784b2f7e8589ff61
82094d
Author: Wander Lairson Costa <wander@redhat.com>
82094d
Date:   Tue Dec 13 08:13:31 2022 -0300
82094d
82094d
    proc: avoid integer type confusion in get_proc_long
82094d
82094d
    Bugzilla: https://bugzilla.redhat.com/2152565
82094d
    CVE: CVE-2022-4378
82094d
82094d
    commit e6cfaf34be9fcd1a8285a294e18986bfc41a409c
82094d
    Author: Linus Torvalds <torvalds@linux-foundation.org>
82094d
    Date:   Mon Dec 5 11:33:40 2022 -0800
82094d
82094d
        proc: avoid integer type confusion in get_proc_long
82094d
82094d
        proc_get_long() is passed a size_t, but then assigns it to an 'int'
82094d
        variable for the length.  Let's not do that, even if our IO paths are
82094d
        limited to MAX_RW_COUNT (exactly because of these kinds of type errors).
82094d
82094d
        So do the proper test in the rigth type.
82094d
82094d
        Reported-by: Kyle Zeng <zengyhkyle@gmail.com>
82094d
        Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
82094d
82094d
    Signed-off-by: Wander Lairson Costa <wander@redhat.com>
82094d
82094d
commit c727ac3f665ed51c096edeedf039552cea6053f6
82094d
Author: Wander Lairson Costa <wander@redhat.com>
82094d
Date:   Tue Dec 13 08:12:23 2022 -0300
82094d
82094d
    proc: proc_skip_spaces() shouldn't think it is working on C strings
82094d
82094d
    Bugzilla: https://bugzilla.redhat.com/2152565
82094d
    CVE: CVE-2022-4378
82094d
82094d
    Conflicts: some context hunks because we are way behind upstream.
82094d
82094d
    commit bce9332220bd677d83b19d21502776ad555a0e73
82094d
    Author: Linus Torvalds <torvalds@linux-foundation.org>
82094d
    Date:   Mon Dec 5 12:09:06 2022 -0800
82094d
82094d
        proc: proc_skip_spaces() shouldn't think it is working on C strings
82094d
82094d
        proc_skip_spaces() seems to think it is working on C strings, and ends
82094d
        up being just a wrapper around skip_spaces() with a really odd calling
82094d
        convention.
82094d
82094d
        Instead of basing it on skip_spaces(), it should have looked more like
82094d
        proc_skip_char(), which really is the exact same function (except it
82094d
        skips a particular character, rather than whitespace).  So use that as
82094d
        inspiration, odd coding and all.
82094d
82094d
        Now the calling convention actually makes sense and works for the
82094d
        intended purpose.
82094d
82094d
        Reported-and-tested-by: Kyle Zeng <zengyhkyle@gmail.com>
82094d
        Acked-by: Eric Dumazet <edumazet@google.com>
82094d
        Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
82094d
82094d
    Signed-off-by: Wander Lairson Costa <wander@redhat.com>
82094d
82094d
Signed-off-by: Ryan Sullivan <rysulliv@redhat.com>
82094d
---
82094d
 kernel/sysctl.c | 36 +++++++++++++++++++++---------------
82094d
 1 file changed, 21 insertions(+), 15 deletions(-)
82094d
82094d
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
82094d
index 62e2788cf09a..6f7d80afda89 100644
82094d
--- a/kernel/sysctl.c
82094d
+++ b/kernel/sysctl.c
82094d
@@ -1999,13 +1999,14 @@ int proc_dostring(struct ctl_table *table, int write,
82094d
 			       (char __user *)buffer, lenp, ppos);
82094d
 }
82094d
 
82094d
-static size_t proc_skip_spaces(char **buf)
82094d
+static void proc_skip_spaces(char **buf, size_t *size)
82094d
 {
82094d
-	size_t ret;
82094d
-	char *tmp = skip_spaces(*buf);
82094d
-	ret = tmp - *buf;
82094d
-	*buf = tmp;
82094d
-	return ret;
82094d
+	while (*size) {
82094d
+		if (!isspace(**buf))
82094d
+			break;
82094d
+		(*size)--;
82094d
+		(*buf)++;
82094d
+	}
82094d
 }
82094d
 
82094d
 static void proc_skip_char(char **buf, size_t *size, const char v)
82094d
@@ -2074,13 +2075,12 @@ static int proc_get_long(char **buf, size_t *size,
82094d
 			  unsigned long *val, bool *neg,
82094d
 			  const char *perm_tr, unsigned perm_tr_len, char *tr)
82094d
 {
82094d
-	int len;
82094d
 	char *p, tmp[TMPBUFLEN];
82094d
+	ssize_t len = *size;
82094d
 
82094d
-	if (!*size)
82094d
+	if (len <= 0)
82094d
 		return -EINVAL;
82094d
 
82094d
-	len = *size;
82094d
 	if (len > TMPBUFLEN - 1)
82094d
 		len = TMPBUFLEN - 1;
82094d
 
82094d
@@ -2250,7 +2250,7 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
82094d
 		bool neg;
82094d
 
82094d
 		if (write) {
82094d
-			left -= proc_skip_spaces(&kbuf);
82094d
+			proc_skip_spaces(&kbuf, &left);
82094d
 
82094d
 			if (!left)
82094d
 				break;
82094d
@@ -2281,7 +2281,7 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
82094d
 	if (!write && !first && left && !err)
82094d
 		err = proc_put_char(&buffer, &left, '\n');
82094d
 	if (write && !err && left)
82094d
-		left -= proc_skip_spaces(&kbuf);
82094d
+		proc_skip_spaces(&kbuf, &left);
82094d
 free:
82094d
 	if (write) {
82094d
 		free_page(page);
82094d
@@ -2331,7 +2331,7 @@ static int do_proc_douintvec_w(unsigned int *tbl_data,
82094d
 	if (IS_ERR(kbuf))
82094d
 		return -EINVAL;
82094d
 
82094d
-	left -= proc_skip_spaces(&p);
82094d
+	proc_skip_spaces(&p, &left);
82094d
 	if (!left) {
82094d
 		err = -EINVAL;
82094d
 		goto out_free;
82094d
@@ -2351,7 +2351,7 @@ static int do_proc_douintvec_w(unsigned int *tbl_data,
82094d
 	}
82094d
 
82094d
 	if (!err && left)
82094d
-		left -= proc_skip_spaces(&p);
82094d
+		proc_skip_spaces(&p, &left);
82094d
 
82094d
 out_free:
82094d
 	kfree(kbuf);
82094d
@@ -2457,6 +2457,7 @@ static int do_proc_douintvec(struct ctl_table *table, int write,
82094d
  *
82094d
  * Returns 0 on success.
82094d
  */
82094d
+__attribute__((optimize("-fno-optimize-sibling-calls")))
82094d
 int proc_dointvec(struct ctl_table *table, int write,
82094d
 		     void __user *buffer, size_t *lenp, loff_t *ppos)
82094d
 {
82094d
@@ -2775,7 +2776,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
82094d
 		if (write) {
82094d
 			bool neg;
82094d
 
82094d
-			left -= proc_skip_spaces(&kbuf);
82094d
+			proc_skip_spaces(&kbuf, &left);
82094d
 
82094d
 			err = proc_get_long(&kbuf, &left, &val, &neg,
82094d
 					     proc_wspace_sep,
82094d
@@ -2800,7 +2801,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
82094d
 	if (!write && !first && left && !err)
82094d
 		err = proc_put_char(&buffer, &left, '\n');
82094d
 	if (write && !err)
82094d
-		left -= proc_skip_spaces(&kbuf);
82094d
+		proc_skip_spaces(&kbuf, &left);
82094d
 free:
82094d
 	if (write) {
82094d
 		free_page(page);
82094d
@@ -2839,6 +2840,7 @@ static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
82094d
  *
82094d
  * Returns 0 on success.
82094d
  */
82094d
+__attribute__((optimize("-fno-optimize-sibling-calls")))
82094d
 int proc_doulongvec_minmax(struct ctl_table *table, int write,
82094d
 			   void __user *buffer, size_t *lenp, loff_t *ppos)
82094d
 {
82094d
@@ -2862,6 +2864,7 @@ int proc_doulongvec_minmax(struct ctl_table *table, int write,
82094d
  *
82094d
  * Returns 0 on success.
82094d
  */
82094d
+__attribute__((optimize("-fno-optimize-sibling-calls")))
82094d
 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
82094d
 				      void __user *buffer,
82094d
 				      size_t *lenp, loff_t *ppos)
82094d
@@ -2957,6 +2960,7 @@ static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
82094d
  *
82094d
  * Returns 0 on success.
82094d
  */
82094d
+__attribute__((optimize("-fno-optimize-sibling-calls")))
82094d
 int proc_dointvec_jiffies(struct ctl_table *table, int write,
82094d
 			  void __user *buffer, size_t *lenp, loff_t *ppos)
82094d
 {
82094d
@@ -2979,6 +2983,7 @@ int proc_dointvec_jiffies(struct ctl_table *table, int write,
82094d
  *
82094d
  * Returns 0 on success.
82094d
  */
82094d
+__attribute__((optimize("-fno-optimize-sibling-calls")))
82094d
 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
82094d
 				 void __user *buffer, size_t *lenp, loff_t *ppos)
82094d
 {
82094d
@@ -3002,6 +3007,7 @@ int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
82094d
  *
82094d
  * Returns 0 on success.
82094d
  */
82094d
+__attribute__((optimize("-fno-optimize-sibling-calls")))
82094d
 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
82094d
 			     void __user *buffer, size_t *lenp, loff_t *ppos)
82094d
 {
82094d
-- 
82094d
2.39.1
82094d
82094d