[PATCH] sysctl: Fix conversion of INT_MIN for LP64 systems
From: Robert Xiao
Date: Sat Jul 11 2015 - 03:34:29 EST
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@xxxxxxxxxx>
---
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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/