diff options
author | Heinrich Schuchardt <xypron.glpk@gmx.de> | 2015-04-16 15:48:07 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-17 09:04:08 -0400 |
commit | 230633d109e35b0a24277498e773edeb79b4a331 (patch) | |
tree | a9619a1bca9f70f5fb0f87b47bdb5493a6e72a8f /kernel | |
parent | 534b483a86e6b96f1b5cc03bbe4b696f3daead6d (diff) |
kernel/sysctl.c: detect overflows when converting to int
When converting unsigned long to int overflows may occur. These currently
are not detected when writing to the sysctl file system.
E.g. on a system where int has 32 bits and long has 64 bits
echo 0x800001234 > /proc/sys/kernel/threads-max
has the same effect as
echo 0x1234 > /proc/sys/kernel/threads-max
The patch adds the missing check in do_proc_dointvec_conv.
With the patch an overflow will result in an error EINVAL when writing to
the the sysctl file system.
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/sysctl.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 3c0998426b57..2082b1a88fb9 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c | |||
@@ -1981,7 +1981,15 @@ static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, | |||
1981 | int write, void *data) | 1981 | int write, void *data) |
1982 | { | 1982 | { |
1983 | if (write) { | 1983 | if (write) { |
1984 | *valp = *negp ? -*lvalp : *lvalp; | 1984 | if (*negp) { |
1985 | if (*lvalp > (unsigned long) INT_MAX + 1) | ||
1986 | return -EINVAL; | ||
1987 | *valp = -*lvalp; | ||
1988 | } else { | ||
1989 | if (*lvalp > (unsigned long) INT_MAX) | ||
1990 | return -EINVAL; | ||
1991 | *valp = *lvalp; | ||
1992 | } | ||
1985 | } else { | 1993 | } else { |
1986 | int val = *valp; | 1994 | int val = *valp; |
1987 | if (val < 0) { | 1995 | if (val < 0) { |