[LTP] [PATCH] sysctl/sysctl03: Test whether return EINVAL when passing negative value

Yang Xu xuyang2018.jy@fujitsu.com
Fri Jan 28 06:51:11 CET 2022


It is a regression for kernel commit
1622ed7d07432 ("sysctl: returns -EINVAL when a negative value is passed to proc_doulongvec_minmax").

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 runtest/commands                      |  1 +
 testcases/commands/sysctl/sysctl03.sh | 52 +++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)
 create mode 100755 testcases/commands/sysctl/sysctl03.sh

diff --git a/runtest/commands b/runtest/commands
index 8cfad0449..c515c7231 100644
--- a/runtest/commands
+++ b/runtest/commands
@@ -41,4 +41,5 @@ gdb01_sh gdb01.sh
 unshare01_sh unshare01.sh
 sysctl01_sh sysctl01.sh
 sysctl02_sh sysctl02.sh
+sysctl03_sh sysctl03.sh
 shell_test01 echo "SUCCESS" | shell_pipe01.sh
diff --git a/testcases/commands/sysctl/sysctl03.sh b/testcases/commands/sysctl/sysctl03.sh
new file mode 100755
index 000000000..ae7bd11c6
--- /dev/null
+++ b/testcases/commands/sysctl/sysctl03.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+# Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+#
+# When we pass a negative value to the proc_doulongvec_minmax() function,
+# the function should return EINVAL and the corresponding interface value
+# does not change.
+#
+# It is also a regression test for
+# commit 1622ed7d0743 ("sysctl: returns -EINVAL when a negative value is passed
+# to proc_doulongvec_minmax").
+#
+# Use fs.epoll.max_user_watches interface to test this.
+
+TST_TESTFUNC=do_test
+TST_SETUP=setup
+TST_NEEDS_ROOT=1
+TST_NEEDS_CMDS="sysctl"
+TST_NEEDS_KCONFIGS="CONFIG_SYSCTL=y, CONFIG_PROC_FS=y, CONFIG_INOTIFY_USER=y"
+sys_name="fs.epoll.max_user_watches"
+sys_file="/proc/sys/fs/epoll/max_user_watches"
+
+. tst_test.sh
+
+setup()
+{
+	orig_value=$(cat "$sys_file")
+}
+
+do_test()
+{
+	tst_res TINFO "trying to set $sys_name=-1"
+
+	sysctl -w -q $sys_name=-1 2>&1 | grep -q "Invalid argument"
+
+	if [ $? -eq 0 ]; then
+		tst_res TPASS "sysctl returns EINVAL when passing a negative value"
+	else
+		tst_res TFAIL "sysctl doesn't return EINVAL when passing a negative value"
+	fi
+
+	new_value=$(cat "$sys_file")
+	if [ $orig_value -eq $new_value ]; then
+		tst_res TPASS "the interface value doesn't change when passing a negative value"
+	else
+		tst_res TFAIL "the interface value changes when passing a negative value"
+		sysctl -w -q $sys_name=$orig_value
+	fi
+}
+
+tst_run
-- 
2.23.0



More information about the ltp mailing list