diff mbox series

[43/69] sysctl: returns -EINVAL when a negative value is passed to proc_doulongvec_minmax

Message ID 20220122061348.oKWIG8D09%akpm@linux-foundation.org (mailing list archive)
State New
Headers show
Series [01/69] mm/migrate.c: rework migration_entry_wait() to not take a pageref | expand

Commit Message

Andrew Morton Jan. 22, 2022, 6:13 a.m. UTC
From: Baokun Li <libaokun1@huawei.com>
Subject: sysctl: returns -EINVAL when a negative value is passed to proc_doulongvec_minmax

When we pass a negative value to the proc_doulongvec_minmax() function,
the function returns 0, but the corresponding interface value does not
change.

we can easily reproduce this problem with the following commands:
    cd /proc/sys/fs/epoll
    echo -1 > max_user_watches; echo $?; cat max_user_watches

This function requires a non-negative number to be passed in, so when
a negative number is passed in, -EINVAL is returned.

Link: https://lkml.kernel.org/r/20211220092627.3744624-1-libaokun1@huawei.com
Signed-off-by: Baokun Li <libaokun1@huawei.com>
Reported-by: Hulk Robot <hulkci@huawei.com>
Acked-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 kernel/sysctl.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff mbox series

Patch

--- a/kernel/sysctl.c~sysctl-returns-einval-when-a-negative-value-is-passed-to-proc_doulongvec_minmax
+++ a/kernel/sysctl.c
@@ -1145,10 +1145,11 @@  static int __do_proc_doulongvec_minmax(v
 			err = proc_get_long(&p, &left, &val, &neg,
 					     proc_wspace_sep,
 					     sizeof(proc_wspace_sep), NULL);
-			if (err)
+			if (err || neg) {
+				err = -EINVAL;
 				break;
-			if (neg)
-				continue;
+			}
+
 			val = convmul * val / convdiv;
 			if ((min && val < *min) || (max && val > *max)) {
 				err = -EINVAL;