Skip to content

Commit e260ad0

Browse files
braunertorvalds
authored andcommitted
sysctl: return -EINVAL if val violates minmax
Currently when userspace gives us a values that overflow e.g. file-max and other callers of __do_proc_doulongvec_minmax() we simply ignore the new value and leave the current value untouched. This can be problematic as it gives the illusion that the limit has indeed be bumped when in fact it failed. This commit makes sure to return EINVAL when an overflow is detected. Please note that this is a userspace facing change. Link: http://lkml.kernel.org/r/20190210203943.8227-4-christian@brauner.io Signed-off-by: Christian Brauner <christian@brauner.io> Acked-by: Luis Chamberlain <mcgrof@kernel.org> Cc: Kees Cook <keescook@chromium.org> Cc: Alexey Dobriyan <adobriyan@gmail.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Dominik Brodowski <linux@dominikbrodowski.net> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Joe Lawrence <joe.lawrence@redhat.com> Cc: Waiman Long <longman@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 475dae3 commit e260ad0

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎kernel/sysctl.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2886,8 +2886,10 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
28862886
if (neg)
28872887
continue;
28882888
val = convmul * val / convdiv;
2889-
if ((min && val < *min) || (max && val > *max))
2890-
continue;
2889+
if ((min && val < *min) || (max && val > *max)) {
2890+
err = -EINVAL;
2891+
break;
2892+
}
28912893
*i = val;
28922894
} else {
28932895
val = convdiv * (*i) / convmul;

0 commit comments

Comments
 (0)