Skip to content

Commit 1622ed7

Browse files
LiBaokun96torvalds
authored andcommitted
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> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e565a8e commit 1622ed7

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

kernel/sysctl.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,10 +1145,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
11451145
err = proc_get_long(&p, &left, &val, &neg,
11461146
proc_wspace_sep,
11471147
sizeof(proc_wspace_sep), NULL);
1148-
if (err)
1148+
if (err || neg) {
1149+
err = -EINVAL;
11491150
break;
1150-
if (neg)
1151-
continue;
1151+
}
1152+
11521153
val = convmul * val / convdiv;
11531154
if ((min && val < *min) || (max && val > *max)) {
11541155
err = -EINVAL;

0 commit comments

Comments
 (0)