]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.4/kernel-sysctl.c-add-missing-range-check-in-do_proc_dointvec_minmax_conv.patch
Linux 3.18.137
[thirdparty/kernel/stable-queue.git] / queue-4.4 / kernel-sysctl.c-add-missing-range-check-in-do_proc_dointvec_minmax_conv.patch
1 From 8cf7630b29701d364f8df4a50e4f1f5e752b2778 Mon Sep 17 00:00:00 2001
2 From: Zev Weiss <zev@bewilderbeest.net>
3 Date: Mon, 11 Mar 2019 23:28:02 -0700
4 Subject: kernel/sysctl.c: add missing range check in do_proc_dointvec_minmax_conv
5
6 From: Zev Weiss <zev@bewilderbeest.net>
7
8 commit 8cf7630b29701d364f8df4a50e4f1f5e752b2778 upstream.
9
10 This bug has apparently existed since the introduction of this function
11 in the pre-git era (4500e91754d3 in Thomas Gleixner's history.git,
12 "[NET]: Add proc_dointvec_userhz_jiffies, use it for proper handling of
13 neighbour sysctls.").
14
15 As a minimal fix we can simply duplicate the corresponding check in
16 do_proc_dointvec_conv().
17
18 Link: http://lkml.kernel.org/r/20190207123426.9202-3-zev@bewilderbeest.net
19 Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
20 Cc: Brendan Higgins <brendanhiggins@google.com>
21 Cc: Iurii Zaikin <yzaikin@google.com>
22 Cc: Kees Cook <keescook@chromium.org>
23 Cc: Luis Chamberlain <mcgrof@kernel.org>
24 Cc: <stable@vger.kernel.org> [2.6.2+]
25 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
26 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
27 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28
29 ---
30 kernel/sysctl.c | 11 ++++++++++-
31 1 file changed, 10 insertions(+), 1 deletion(-)
32
33 --- a/kernel/sysctl.c
34 +++ b/kernel/sysctl.c
35 @@ -2306,7 +2306,16 @@ static int do_proc_dointvec_minmax_conv(
36 {
37 struct do_proc_dointvec_minmax_conv_param *param = data;
38 if (write) {
39 - int val = *negp ? -*lvalp : *lvalp;
40 + int val;
41 + if (*negp) {
42 + if (*lvalp > (unsigned long) INT_MAX + 1)
43 + return -EINVAL;
44 + val = -*lvalp;
45 + } else {
46 + if (*lvalp > (unsigned long) INT_MAX)
47 + return -EINVAL;
48 + val = *lvalp;
49 + }
50 if ((param->min && *param->min > val) ||
51 (param->max && *param->max < val))
52 return -EINVAL;