linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Luis R. Rodriguez" <mcgrof@kernel.org>
To: gregkh@linuxfoundation.org, viro@zeniv.linux.org.uk,
	philipp.reisner@linbit.com, lars.ellenberg@linbit.com,
	axboe@kernel.dk, bfields@fieldses.org, chuck.lever@oracle.com,
	roopa@cumulusnetworks.com, nikolay@cumulusnetworks.com,
	davem@davemloft.net, kuba@kernel.org, dhowells@redhat.com,
	jarkko.sakkinen@linux.intel.com, jmorris@namei.org,
	serge@hallyn.com, christian.brauner@ubuntu.com
Cc: slyfox@gentoo.org, ast@kernel.org, keescook@chromium.org,
	josh@joshtriplett.org, ravenexp@gmail.com, chainsaw@gentoo.org,
	linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org,
	bridge@lists.linux-foundation.org, keyrings@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Luis Chamberlain <mcgrof@kernel.org>,
	Tiezhu Yang <yangtiezhu@loongson.cn>
Subject: [PATCH 5/5] selftests: simplify kmod failure value
Date: Wed, 10 Jun 2020 15:49:23 +0000	[thread overview]
Message-ID: <20200610154923.27510-6-mcgrof@kernel.org> (raw)
In-Reply-To: <20200610154923.27510-1-mcgrof@kernel.org>

From: Luis Chamberlain <mcgrof@kernel.org>

The "odd" 256 value was just an issue with the umh never
wrapping it around with WEXITSTATUS() for us. Now that it
does that, we can use a sane value / name for the selftest,
and this is no longer a oddity.

We add a way to detect this for older kernels, and support
the old return value for kernel code where it was given.

This never affected userspace.

Reported-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 tools/testing/selftests/kmod/kmod.sh | 46 +++++++++++++++++++++++-----
 1 file changed, 39 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/kmod/kmod.sh b/tools/testing/selftests/kmod/kmod.sh
index da60c3bd4f23..df7b21d8561c 100755
--- a/tools/testing/selftests/kmod/kmod.sh
+++ b/tools/testing/selftests/kmod/kmod.sh
@@ -64,6 +64,8 @@ ALL_TESTS="$ALL_TESTS 0009:150:1"
 ALL_TESTS="$ALL_TESTS 0010:1:1"
 ALL_TESTS="$ALL_TESTS 0011:1:1"
 
+MODULE_NOT_FOUND="FAILURE"
+
 # Kselftest framework requirement - SKIP code is 4.
 ksft_skip=4
 
@@ -155,14 +157,19 @@ test_finish()
 	echo "Test completed"
 }
 
+# OLD_FAILURE is just because the old kernel umh never wrapped
+# the error with WEXITSTATUS(). Now that it does it, we get the
+# appropriate actual value from userspace observed in-kernel.
+
+# We keep the old mapping to ensure this script keeps working
+# with older kernels.
 errno_name_to_val()
 {
 	case "$1" in
-	# kmod calls modprobe and upon of a module not found
-	# modprobe returns just 1... However in the kernel we
-	# *sometimes* see 256...
-	MODULE_NOT_FOUND)
+	OLD_FAILURE)
 		echo 256;;
+	FAILURE)
+		echo 1;;
 	SUCCESS)
 		echo 0;;
 	-EPERM)
@@ -181,7 +188,9 @@ errno_name_to_val()
 errno_val_to_name()
 	case "$1" in
 	256)
-		echo MODULE_NOT_FOUND;;
+		echo OLD_FAILURE;;
+	1)
+		echo FAILURE;;
 	0)
 		echo SUCCESS;;
 	-1)
@@ -335,6 +344,28 @@ kmod_defaults_fs()
 	config_set_test_case_fs
 }
 
+check_umh()
+{
+	NAME=''
+
+	kmod_defaults_driver
+	config_num_threads 1
+	printf '\0' >"$DIR"/config_test_driver
+	config_trigger ${FUNCNAME[0]}
+	RC=$(config_get_test_result)
+	if [[ "$RC" == "256" ]]; then
+		MODULE_NOT_FOUND="OLD_FAILURE"
+		echo "check_umh: you have and old umh which didn't wrap errors"
+		echo "           with WEXITSTATUS(). This is OK!"
+	elif [[ "$RC" != "1" ]]; then
+		echo "check_umh: Unexpected return value with no modprobe argument: $RC"
+		exit
+	else
+		echo "check_umh: You have a new umh which wraps erros with"
+		echo "           WEXITSTATUS(). This is OK!"
+	fi
+}
+
 kmod_test_0001_driver()
 {
 	NAME='\000'
@@ -343,7 +374,7 @@ kmod_test_0001_driver()
 	config_num_threads 1
 	printf $NAME >"$DIR"/config_test_driver
 	config_trigger ${FUNCNAME[0]}
-	config_expect_result ${FUNCNAME[0]} MODULE_NOT_FOUND
+	config_expect_result ${FUNCNAME[0]} $MODULE_NOT_FOUND
 }
 
 kmod_test_0001_fs()
@@ -371,7 +402,7 @@ kmod_test_0002_driver()
 	config_set_driver $NAME
 	config_num_threads 1
 	config_trigger ${FUNCNAME[0]}
-	config_expect_result ${FUNCNAME[0]} MODULE_NOT_FOUND
+	config_expect_result ${FUNCNAME[0]} $MODULE_NOT_FOUND
 }
 
 kmod_test_0002_fs()
@@ -648,6 +679,7 @@ load_req_mod
 MODPROBE=$(</proc/sys/kernel/modprobe)
 trap "test_finish" EXIT
 
+check_umh
 parse_args $@
 
 exit 0
-- 
2.26.2


  parent reply	other threads:[~2020-06-10 15:50 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-10 15:49 [PATCH 0/5] kmod/umh: a few fixes Luis R. Rodriguez
2020-06-10 15:49 ` [PATCH 1/5] selftests: kmod: Use variable NAME in kmod_test_0001() Luis R. Rodriguez
2020-06-10 15:49 ` [PATCH 2/5] kmod: Remove redundant "be an" in the comment Luis R. Rodriguez
2020-06-10 15:49 ` [PATCH 3/5] test_kmod: Avoid potential double free in trigger_config_run_type() Luis R. Rodriguez
2020-06-10 15:49 ` [PATCH 4/5] umh: fix processed error when UMH_WAIT_PROC is used Luis R. Rodriguez
2020-06-23 14:11   ` linux-next: umh: fix processed error when UMH_WAIT_PROC is used seems to break linux bridge on s390x (bisected) Christian Borntraeger
2020-06-23 14:23     ` Christian Borntraeger
2020-06-24 11:11       ` Christian Borntraeger
2020-06-24 12:05         ` Luis Chamberlain
2020-06-24 13:17           ` Luis Chamberlain
2020-06-24 16:13             ` Luis Chamberlain
2020-06-24 14:43         ` Christoph Hellwig
2020-06-24 15:54           ` Christian Borntraeger
2020-06-24 16:09             ` Luis Chamberlain
2020-06-24 17:58               ` Christian Borntraeger
2020-06-24 18:09                 ` Christian Borntraeger
2020-06-24 18:32                   ` Christian Borntraeger
2020-06-24 18:37                     ` Christian Borntraeger
2020-06-25 13:26                       ` Christian Borntraeger
2020-06-26  2:54                       ` Luis Chamberlain
2020-06-26  5:22                         ` Christian Borntraeger
2020-06-26  9:00                           ` Christoph Hellwig
2020-06-26 11:40                             ` Luis Chamberlain
2020-06-26 11:50                               ` Luis Chamberlain
2020-06-30 17:57                         ` Luis Chamberlain
2020-07-01 10:08                           ` Christian Borntraeger
2020-07-01 13:24                             ` Tetsuo Handa
2020-07-01 13:53                               ` Luis Chamberlain
2020-07-01 14:08                                 ` Tetsuo Handa
2020-07-01 15:38                                   ` Luis Chamberlain
2020-07-01 15:48                                     ` Christian Borntraeger
2020-07-01 15:58                                       ` Luis Chamberlain
2020-07-01 16:01                                         ` Christian Borntraeger
2020-07-02  4:26                                     ` Tetsuo Handa
2020-07-02 19:46                                       ` Luis Chamberlain
2020-07-03  0:52                                         ` Tetsuo Handa
2020-07-03 13:28                                           ` Luis Chamberlain
2020-07-01 15:26                                 ` Christian Borntraeger
2020-07-01 13:46                             ` Luis Chamberlain
2020-06-10 15:49 ` Luis R. Rodriguez [this message]
2020-06-18  0:43 ` [PATCH 0/5] kmod/umh: a few fixes Andrew Morton
2020-06-19 20:46   ` Luis Chamberlain
2020-06-19 21:07     ` Luis Chamberlain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200610154923.27510-6-mcgrof@kernel.org \
    --to=mcgrof@kernel.org \
    --cc=ast@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=bfields@fieldses.org \
    --cc=bridge@lists.linux-foundation.org \
    --cc=chainsaw@gentoo.org \
    --cc=christian.brauner@ubuntu.com \
    --cc=chuck.lever@oracle.com \
    --cc=davem@davemloft.net \
    --cc=dhowells@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=jmorris@namei.org \
    --cc=josh@joshtriplett.org \
    --cc=keescook@chromium.org \
    --cc=keyrings@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=lars.ellenberg@linbit.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=nikolay@cumulusnetworks.com \
    --cc=philipp.reisner@linbit.com \
    --cc=ravenexp@gmail.com \
    --cc=roopa@cumulusnetworks.com \
    --cc=serge@hallyn.com \
    --cc=slyfox@gentoo.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=yangtiezhu@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).