The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] sysctl: Fix conversion of INT_MIN for LP64 systems
@ 2015-07-11  6:56 Robert Xiao
  0 siblings, 0 replies; 4+ messages in thread
From: Robert Xiao @ 2015-07-11  6:56 UTC (permalink / raw)
  To: LKML <linux-kernel@vger.kernel.org>; Mikulas Patocka <mikulas@twibright.com>; Ilya Dryomov
  Cc: Robert Xiao

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [PATCH] sysctl: Fix conversion of INT_MIN for LP64 systems
@ 2015-07-11  7:34 Robert Xiao
  0 siblings, 0 replies; 4+ messages in thread
From: Robert Xiao @ 2015-07-11  7:34 UTC (permalink / raw)
  To: LKML <linux-kernel@vger.kernel.org>; Mikulas Patocka <mikulas@twibright.com>; Ilya Dryomov <idryomov@gmail.com>; Robert Xiao <brx@cs.cmu.edu>; Robert Xiao
  Cc: Robert Xiao

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [PATCH] sysctl: Fix conversion of INT_MIN for LP64 systems
@ 2015-07-11  7:35 Robert Xiao
  2015-07-11 17:15 ` Ilya Dryomov
  0 siblings, 1 reply; 4+ messages in thread
From: Robert Xiao @ 2015-07-11  7:35 UTC (permalink / raw)
  To: LKML <linux-kernel@vger.kernel.org>; Mikulas Patocka <mikulas@twibright.com>; Ilya Dryomov <idryomov@gmail.com>; Robert Xiao <brx@cs.cmu.edu>; Robert Xiao
  Cc: Robert Xiao

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-07-11 17:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-11  6:56 [PATCH] sysctl: Fix conversion of INT_MIN for LP64 systems Robert Xiao
  -- strict thread matches above, loose matches on Subject: below --
2015-07-11  7:34 Robert Xiao
2015-07-11  7:35 Robert Xiao
2015-07-11 17:15 ` Ilya Dryomov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox