Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1530640

[RFC] kernel/sysctl.c: return -EINVAL when write invalid val to ulong type sysctl

From Yisheng Xie <xieyisheng1@huawei.com>
Newsgroups linux.kernel
Subject [RFC] kernel/sysctl.c: return -EINVAL when write invalid val to ulong type sysctl
Date 2016-11-26 10:20 +0100
Message-ID <sHHjk-4Am-13@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


I tried to echo an invalid value to an unsigned long type sysctl on 4.9.0-rc6:
   linux:~# cat /proc/sys/vm/user_reserve_kbytes
   131072
   linux:~# echo -1 > /proc/sys/vm/user_reserve_kbytes
   linux:~# cat /proc/sys/vm/user_reserve_kbytes
   131072

The echo operation got error and the value do not write to user_reserve_kbytes,
however, user do not know it until check the value again.

Is it more suitable to return -EINVAL when echo an invalid value to an unsigned long
type sysctl, in order to let user know what happened without checking its value once more?
Just as what int type sysctl do:
   linux:~#cat /proc/sys/kernel/sysctl_writes_strict
   1
   linux:~# echo 3 > /proc/sys/kernel/sysctl_writes_strict
   bash: echo: write error: Invalid argument

----------------------
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 706309f..40e9285 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2485,10 +2485,14 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
                                             sizeof(proc_wspace_sep), NULL);
                        if (err)
                                break;
-                       if (neg)
-                               continue;
-                       if ((min && val < *min) || (max && val > *max))
-                               continue;
+                       if (neg) {
+                               err = -EINVAL;
+                               break;
+                       }
+                       if ((min && val < *min) || (max && val > *max)) {
+                               err = -EINVAL;
+                               break;
+                       }
                        *i = val;
                } else {
                        val = convdiv * (*i) / convmul;

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[RFC] kernel/sysctl.c: return -EINVAL when write invalid val to ulong  type sysctl Yisheng Xie <xieyisheng1@huawei.com> - 2016-11-26 10:20 +0100
  Re: [RFC] kernel/sysctl.c: return -EINVAL when write invalid val to  ulong type sysctl subashab@codeaurora.org - 2016-11-27 00:20 +0100
    Re: [RFC] kernel/sysctl.c: return -EINVAL when write invalid val to  ulong type sysctl Yisheng Xie <xieyisheng1@huawei.com> - 2016-11-29 11:30 +0100

csiph-web