lkml.org 
[lkml]   [2015]   [Jul]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] sysctl: Fix conversion of INT_MIN for LP64 systems
Date
On LP64 systems, reading a sysctl file containing an INT_MIN (-2147483648)
could incorrectly show -18446744071562067968 due to an incorrect conversion
in do_proc_dointvec_conv. This patch fixes the edge case by converting to
unsigned int first to avoid sign extending INT_MIN to unsigned long.

Test:

root:/proc/sys/kernel# echo -2147483648 0 0 0 > printk
root:/proc/sys/kernel# cat printk

Without patch, produces -18446744071562067968 0 0 0.
With patch, should produce -2147483648 0 0 0.

Signed-off-by: Robert Xiao <brx@cs.cmu.edu>
---
kernel/sysctl.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 19b62b5..464df36 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1995,10 +1995,10 @@ static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
int val = *valp;
if (val < 0) {
*negp = true;
- *lvalp = (unsigned long)-val;
+ *lvalp = (unsigned int)-val;
} else {
*negp = false;
- *lvalp = (unsigned long)val;
+ *lvalp = (unsigned int)val;
}
}
return 0;
--
2.2.2

\
 
 \ /
  Last update: 2015-07-11 10:01    [W:0.044 / U:1.092 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site