public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Gregory Price <gourry@gourry.net>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: krisman@collabora.com, tglx@linutronix.de, luto@kernel.org,
	peterz@infradead.org, keescook@chromium.org,
	gregory.price@memverge.com, Marco Elver <elver@google.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] selftests: Extend syscall_user_dispatch test to check allowed range
Date: Thu, 20 Feb 2025 10:17:29 -0500	[thread overview]
Message-ID: <Z7dHid-IL7OAPmUa@gourry-fedora-PF4VCD3F> (raw)
In-Reply-To: <5e105b1382cd43d05f1d3a80958e4f50f32144c8.1739894594.git.dvyukov@google.com>

On Tue, Feb 18, 2025 at 05:04:36PM +0100, Dmitry Vyukov wrote:
> diff --git a/tools/testing/selftests/syscall_user_dispatch/sud_test.c b/tools/testing/selftests/syscall_user_dispatch/sud_test.c
> index b0969925ec64c..fa40e46e6d3e9 100644
> --- a/tools/testing/selftests/syscall_user_dispatch/sud_test.c
> +++ b/tools/testing/selftests/syscall_user_dispatch/sud_test.c
... snip ...
> @@ -110,31 +111,15 @@ TEST(bad_prctl_param)
>  	/* PR_SYS_DISPATCH_ON */
>  	op = PR_SYS_DISPATCH_ON;
>  
> -	/* Dispatcher region is bad (offset > 0 && len == 0) */
> -	EXPECT_EQ(-1, prctl(PR_SET_SYSCALL_USER_DISPATCH, op, 0x1, 0x0, &sel));
> -	EXPECT_EQ(EINVAL, errno);
> -	EXPECT_EQ(-1, prctl(PR_SET_SYSCALL_USER_DISPATCH, op, -1L, 0x0, &sel));
> -	EXPECT_EQ(EINVAL, errno);
> +	/* All ranges are allowed */
> +	EXPECT_EQ(0, prctl(PR_SET_SYSCALL_USER_DISPATCH, op, 0x1, 0x0, &sel));
> +	EXPECT_EQ(0, prctl(PR_SET_SYSCALL_USER_DISPATCH, op, -1L, 0x0, &sel));

A 0 length is ambiguous and nonsensical in every other context, not sure
why you'd allow it here.

... snip ...

> +bool test_range(unsigned long offset, unsigned long length)
> +{
> +	nr_syscalls_emulated = 0;
> +	if (prctl(PR_SET_SYSCALL_USER_DISPATCH, PR_SYS_DISPATCH_ON, offset, length, &glob_sel))
> +		return false;

This creates an ambiguous failure state for your test. Is it failing
because the range is bad or because you didn't intercept a syscall?

Better to be more explicit here. It makes it difficult to understand
what each individual test is doing at a glance.

> +	SYSCALL_DISPATCH_ON(glob_sel);
> +	return syscall(MAGIC_SYSCALL_1) == MAGIC_SYSCALL_1 && nr_syscalls_emulated == 1;
> +}
> +
> +TEST(dispatch_range)
> +{
> +	ASSERT_EQ(0, setup_sigsys_handler());
> +	ASSERT_EQ(0, prctl(PR_SET_SYSCALL_USER_DISPATCH, PR_SYS_DISPATCH_ON, 0, 0, &glob_sel));
> +	SYSCALL_DISPATCH_ON(glob_sel);
> +	ASSERT_EQ(MAGIC_SYSCALL_1, syscall(MAGIC_SYSCALL_1));
> +	TH_LOG("syscall_addr=0x%lx", syscall_addr);
> +	EXPECT_FALSE(test_range(syscall_addr, 1));
> +	EXPECT_FALSE(test_range(syscall_addr-100, 200));
> +	EXPECT_TRUE(test_range(syscall_addr+1, 100));
> +	EXPECT_TRUE(test_range(syscall_addr-100, 100));
> +	/* Wrap-around tests for everything except for a single PC. */
> +	EXPECT_TRUE(test_range(syscall_addr+1, -1));
> +	EXPECT_FALSE(test_range(syscall_addr, -1));
> +	EXPECT_FALSE(test_range(syscall_addr+2, -1));

If you are planning to include 0 as an allowed length, you need to
demonstrate what it does.

> +	SYSCALL_DISPATCH_OFF(glob_sel);
> +}
> +
>  TEST_HARNESS_MAIN
> -- 
> 2.48.1.601.g30ceb7b040-goog
> 

  reply	other threads:[~2025-02-20 15:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1739894594.git.dvyukov@google.com>
2025-02-18 16:04 ` [PATCH 1/3] syscall_user_dispatch: Allow allowed range wrap-around Dmitry Vyukov
2025-02-18 16:58   ` Gregory Price
2025-02-18 17:34     ` Dmitry Vyukov
2025-02-18 18:00       ` Gregory Price
2025-02-19  8:54         ` Dmitry Vyukov
2025-02-19 13:29           ` Gregory Price
2025-02-18 16:04 ` [PATCH 2/3] selftests: Fix errno checking in syscall_user_dispatch test Dmitry Vyukov
2025-02-19 17:19   ` Kees Cook
2025-02-18 16:04 ` [PATCH 3/3] selftests: Extend syscall_user_dispatch test to check allowed range Dmitry Vyukov
2025-02-20 15:17   ` Gregory Price [this message]
2025-02-24  8:48     ` Dmitry Vyukov
2025-03-03 15:57       ` Gregory Price

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=Z7dHid-IL7OAPmUa@gourry-fedora-PF4VCD3F \
    --to=gourry@gourry.net \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=gregory.price@memverge.com \
    --cc=keescook@chromium.org \
    --cc=krisman@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /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