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]
Date:   Wed, 30 Nov 2016 18:30:52 +0800
From:   Yisheng Xie <xieyisheng1@...wei.com>
To:     <linux-kernel@...r.kernel.org>
CC:     <akpm@...ux-foundation.org>, <acme@...hat.com>,
        <mgorman@...hsingularity.net>, <viro@...iv.linux.org.uk>,
        <hannes@...xchg.org>, <ebiederm@...ssion.com>,
        <bristot@...hat.com>, <subashab@...eaurora.org>,
        <dcashman@...gle.com>, <w@....eu>, <arnd@...db.de>,
        <guohanjun@...wei.com>, <qiuxishi@...wei.com>
Subject: [PATCH] kernel/sysctl: return -EINVAL if 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 checking
the value again.

This patch return -EINVAL when write an invalid value to unsigned
long type sysctl to make user know  what happened without
checking its value once more, just as what proc_douintvec do.

Signed-off-by: Yisheng Xie <xieyisheng1@...wei.com>
---
This is a patchset after RFC, you can see the former discussion at
https://lkml.org/lkml/2016/11/26/48

Any comment is more than welcome.

Thanks,
Yisheng Xie.
---
 kernel/sysctl.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

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;
-- 
1.7.12.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ