lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <669ac5a2-8b2f-5a47-305d-f6cf7cff4f63@huawei.com>
Date:   Sat, 26 Nov 2016 17:13:02 +0800
From:   Yisheng Xie <xieyisheng1@...wei.com>
To:     Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
CC:     Andrew Morton <akpm@...ux-foundation.org>,
        Arnaldo Carvalho de Melo <acme@...hat.com>,
        Mel Gorman <mgorman@...hsingularity.net>,
        Al Viro <viro@...iv.linux.org.uk>,
        Johannes Weiner <hannes@...xchg.org>,
        "Eric W. Biederman" <ebiederm@...ssion.com>,
        Daniel Bristot de Oliveira <bristot@...hat.com>,
        Subash Abhinov Kasiviswanathan <subashab@...eaurora.org>,
        Daniel Cashman <dcashman@...gle.com>,
        "Willy Tarreau" <w@....eu>, Arnd Bergmann <arnd@...db.de>,
        Hanjun Guo <guohanjun@...wei.com>,
        Xishi Qiu <qiuxishi@...wei.com>
Subject: [RFC] kernel/sysctl.c: return -EINVAL when write invalid val to ulong
 type sysctl

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;



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ