]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
proc/sysctl: fix the int overflow for jiffies conversion
authorGao Feng <fgao@ikuai8.com>
Mon, 8 May 2017 22:54:58 +0000 (15:54 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 9 May 2017 00:15:10 +0000 (17:15 -0700)
do_proc_dointvec_jiffies_conv() uses LONG_MAX/HZ as the max value to
avoid overflow.  But actually the *valp is int type, so it still causes
overflow.

For example,

  echo 2147483647 > ./sys/net/ipv4/tcp_keepalive_time

Then,

  cat ./sys/net/ipv4/tcp_keepalive_time

The output is "-1", it is not expected.

Now use INT_MAX/HZ as the max value instead LONG_MAX/HZ to fix it.

Link: http://lkml.kernel.org/r/1490109532-9228-1-git-send-email-fgao@ikuai8.com
Signed-off-by: Gao Feng <fgao@ikuai8.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
kernel/sysctl.c

index 21343d1102963485eb9d706012be8d4cc5752edf..4dfba1a76cc360f649cbe6f35b57cf9413f2f5e1 100644 (file)
@@ -2576,7 +2576,7 @@ static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
                                         int write, void *data)
 {
        if (write) {
-               if (*lvalp > LONG_MAX / HZ)
+               if (*lvalp > INT_MAX / HZ)
                        return 1;
                *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
        } else {