]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - queue-4.14/sysctl-return-einval-if-val-violates-minmax.patch
Merge branch 'master' of gitolite.kernel.org:/pub/scm/linux/kernel/git/stable/stable...
[thirdparty/kernel/stable-queue.git] / queue-4.14 / sysctl-return-einval-if-val-violates-minmax.patch
CommitLineData
6e4ffbcf
SL
1From 34c151fde52a22d6b02c2fe85542e393ee5ac0b3 Mon Sep 17 00:00:00 2001
2From: Christian Brauner <christian@brauner.io>
3Date: Tue, 14 May 2019 15:44:55 -0700
4Subject: sysctl: return -EINVAL if val violates minmax
5
6[ Upstream commit e260ad01f0aa9e96b5386d5cd7184afd949dc457 ]
7
8Currently when userspace gives us a values that overflow e.g. file-max
9and other callers of __do_proc_doulongvec_minmax() we simply ignore the
10new value and leave the current value untouched.
11
12This can be problematic as it gives the illusion that the limit has
13indeed be bumped when in fact it failed. This commit makes sure to
14return EINVAL when an overflow is detected. Please note that this is a
15userspace facing change.
16
17Link: http://lkml.kernel.org/r/20190210203943.8227-4-christian@brauner.io
18Signed-off-by: Christian Brauner <christian@brauner.io>
19Acked-by: Luis Chamberlain <mcgrof@kernel.org>
20Cc: Kees Cook <keescook@chromium.org>
21Cc: Alexey Dobriyan <adobriyan@gmail.com>
22Cc: Al Viro <viro@zeniv.linux.org.uk>
23Cc: Dominik Brodowski <linux@dominikbrodowski.net>
24Cc: "Eric W. Biederman" <ebiederm@xmission.com>
25Cc: Joe Lawrence <joe.lawrence@redhat.com>
26Cc: Waiman Long <longman@redhat.com>
27Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
28Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
29Signed-off-by: Sasha Levin <sashal@kernel.org>
30---
31 kernel/sysctl.c | 6 ++++--
32 1 file changed, 4 insertions(+), 2 deletions(-)
33
34diff --git a/kernel/sysctl.c b/kernel/sysctl.c
35index f13601a616ad..cfc2c0d1369a 100644
36--- a/kernel/sysctl.c
37+++ b/kernel/sysctl.c
38@@ -2732,8 +2732,10 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
39 if (neg)
40 continue;
41 val = convmul * val / convdiv;
42- if ((min && val < *min) || (max && val > *max))
43- continue;
44+ if ((min && val < *min) || (max && val > *max)) {
45+ err = -EINVAL;
46+ break;
47+ }
48 *i = val;
49 } else {
50 val = convdiv * (*i) / convmul;
51--
522.20.1
53