proc: avoid integer type confusion in get_proc_long
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 5 Dec 2022 19:33:40 +0000 (11:33 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 8 Dec 2022 10:15:42 +0000 (11:15 +0100)
commit e6cfaf34be9fcd1a8285a294e18986bfc41a409c upstream.

proc_get_long() is passed a size_t, but then assigns it to an 'int'
variable for the length.  Let's not do that, even if our IO paths are
limited to MAX_RW_COUNT (exactly because of these kinds of type errors).

So do the proper test in the rigth type.

Reported-by: Kyle Zeng <zengyhkyle@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/sysctl.c

index 184d462339e6585c7f292dab5d63ef281aace38e..bbd0876e100b3907127d4856b8cb5086d5d3fa66 100644 (file)
@@ -2081,13 +2081,12 @@ static int proc_get_long(char **buf, size_t *size,
                          unsigned long *val, bool *neg,
                          const char *perm_tr, unsigned perm_tr_len, char *tr)
 {
-       int len;
        char *p, tmp[TMPBUFLEN];
+       ssize_t len = *size;
 
-       if (!*size)
+       if (len <= 0)
                return -EINVAL;
 
-       len = *size;
        if (len > TMPBUFLEN - 1)
                len = TMPBUFLEN - 1;