Linux-kselftest Archive on lore.kernel.org
 help / color / Atom feed
From: Eugene Syromiatnikov <esyr@redhat.com>
To: linux-kernel@vger.kernel.org,
	Christian Brauner <christian@brauner.io>,
	Shuah Khan <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org
Cc: Adrian Reber <areber@redhat.com>
Subject: [PATCH v2 2/6] selftests/clone3: add a check for invalid exit_signal
Date: Tue, 10 Sep 2019 19:01:46 +0100
Message-ID: <ce747456484914abb9f415d87751e49a05763b51.1568138393.git.esyr@redhat.com> (raw)
In-Reply-To: <cover.1568138393.git.esyr@redhat.com>

Check that the kernel fails calls with exit_signal with non-zero highest
32 bits, negative 32-bit exit_signal, and not failing on passing
invalid exit_signal withing CSIGNAL mask, like legacy clone syscalls do.

* tools/testing/selftests/clone3/clone3.c (enum test_mode): Add
CLONE3_ARGS_INVAL_EXIT_SIGNAL_BIG, CLONE3_ARGS_INVAL_EXIT_SIGNAL_NEG,
CLONE3_ARGS_INVAL_EXIT_SIGNAL_CSIG, CLONE3_ARGS_INVAL_EXIT_SIGNAL_NSIG.
(call_clone3): Add args.exit_signal initialisation in case test_mode
is equal to one of the added enum test_mode values.
(main): Add test_clone3 clone check with test_mode equal to the added
enum test_mode values.

Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
---
 tools/testing/selftests/clone3/clone3.c | 36 +++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/tools/testing/selftests/clone3/clone3.c b/tools/testing/selftests/clone3/clone3.c
index 7b65ee5..318189f9 100644
--- a/tools/testing/selftests/clone3/clone3.c
+++ b/tools/testing/selftests/clone3/clone3.c
@@ -28,6 +28,10 @@ enum test_mode {
 	CLONE3_ARGS_NO_TEST,
 	CLONE3_ARGS_ALL_0,
 	CLONE3_ARGS_ALL_1,
+	CLONE3_ARGS_INVAL_EXIT_SIGNAL_BIG,
+	CLONE3_ARGS_INVAL_EXIT_SIGNAL_NEG,
+	CLONE3_ARGS_INVAL_EXIT_SIGNAL_CSIG,
+	CLONE3_ARGS_INVAL_EXIT_SIGNAL_NSIG,
 };
 
 static pid_t raw_clone(struct clone_args *args, size_t size)
@@ -72,6 +76,22 @@ static int call_clone3(int flags, size_t size, enum test_mode test_mode)
 		args.tls = 1;
 		args.set_tid = 1;
 		break;
+
+	case CLONE3_ARGS_INVAL_EXIT_SIGNAL_BIG:
+		args.exit_signal = 0xbadc0ded00000000ULL;
+		break;
+
+	case CLONE3_ARGS_INVAL_EXIT_SIGNAL_NEG:
+		args.exit_signal = 0x0000000080000000ULL;
+		break;
+
+	case CLONE3_ARGS_INVAL_EXIT_SIGNAL_CSIG:
+		args.exit_signal = 0x0000000000000100ULL;
+		break;
+
+	case CLONE3_ARGS_INVAL_EXIT_SIGNAL_NSIG:
+		args.exit_signal = 0x00000000000000f0ULL;
+		break;
 	}
 
 	pid = raw_clone(&args, size);
@@ -146,6 +166,22 @@ int main(int argc, char *argv[])
 	/* Do a clone3() with all members set to 1 */
 	if (test_clone3(0, CLONE3_ARGS_SIZE_V0, -EINVAL, CLONE3_ARGS_ALL_1))
 		goto on_error;
+	/* Do a clone3() with exit_signal having highest 32 bits non-zero */
+	if (test_clone3(0, CLONE3_ARGS_SIZE_V0, -EINVAL,
+			CLONE3_ARGS_INVAL_EXIT_SIGNAL_BIG))
+		goto on_error;
+	/* Do a clone3() with negative 32-bit exit_signal */
+	if (test_clone3(0, CLONE3_ARGS_SIZE_V0, -EINVAL,
+			CLONE3_ARGS_INVAL_EXIT_SIGNAL_NEG))
+		goto on_error;
+	/* Do a clone3() with exit_signal not fitting into CSIGNAL mask */
+	if (test_clone3(0, CLONE3_ARGS_SIZE_V0, -EINVAL,
+			CLONE3_ARGS_INVAL_EXIT_SIGNAL_CSIG))
+		goto on_error;
+	/* Do a clone3() with NSIG < exit_signal < CSIG */
+	if (test_clone3(0, CLONE3_ARGS_SIZE_V0, 0,
+			CLONE3_ARGS_INVAL_EXIT_SIGNAL_NSIG))
+		goto on_error;
 	/*
 	 * Do a clone3() with sizeof(struct clone_args) + 8
 	 * and all members set to 0.
-- 
2.1.4


  parent reply index

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-10 18:01 [PATCH v2 0/6] Update clone3 self-tests Eugene Syromiatnikov
2019-09-10 18:01 ` [PATCH v2 1/6] selftests/clone3: convert test modes into an enum Eugene Syromiatnikov
2019-09-10 18:01 ` Eugene Syromiatnikov [this message]
2019-09-10 18:01 ` [PATCH v2 3/6] selftests/clone3: use uint64_t for flags parameter Eugene Syromiatnikov
2019-09-10 18:02 ` [PATCH v2 4/6] selftests/clone3: fix up format strings Eugene Syromiatnikov
2019-09-10 18:02 ` [PATCH v2 5/6] selftests/clone3: enable clone3 self-tests on all architectures Eugene Syromiatnikov
2019-09-10 18:02 ` [PATCH v2 6/6] selftests: add clone3 to TARGETS Eugene Syromiatnikov
2019-09-16  7:49 ` [PATCH v2 0/6] Update clone3 self-tests Christian Brauner
2019-09-16  8:12   ` Adrian Reber
2019-09-16  8:14     ` Christian Brauner

Reply instructions:

You may reply publically 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=ce747456484914abb9f415d87751e49a05763b51.1568138393.git.esyr@redhat.com \
    --to=esyr@redhat.com \
    --cc=areber@redhat.com \
    --cc=christian@brauner.io \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    /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

Linux-kselftest Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-kselftest/0 linux-kselftest/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-kselftest linux-kselftest/ https://lore.kernel.org/linux-kselftest \
		linux-kselftest@vger.kernel.org linux-kselftest@archiver.kernel.org
	public-inbox-index linux-kselftest

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kselftest


AGPL code for this site: git clone https://public-inbox.org/ public-inbox