Skip to contentSkip to conversation

proc/sysctl: fix the int overflow for jiffies conversion

PATCH New [email protected] 1 participant 1 message May 8, 2017 Proc sysctl

lore
Share & tools
lore
#0 lore raw

PATCH 10/114 proc/sysctl: fix the int overflow for jiffies conversion

From: Gao Feng <[email protected]>
Subject: proc/sysctl: fix the int overflow for jiffies conversion

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.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Alexey Dobriyan <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Josh Poimboeuf <[email protected]>

---

 kernel/sysctl.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sysctl.c renamed from kernel/sysctl.c~proc-sysctl-fix-the-int-overflow-for-jiffies-conversion +1 -1
diff -puN kernel/sysctl.c~proc-sysctl-fix-the-int-overflow-for-jiffies-conversion kernel/sysctl.c
@@ -2576,7 +2576,7 @@ static int do_proc_dointvec_jiffies_conv
 					 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 {

_