The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Mickaël Salaün" <mic@digikod.net>
To: "Günther Noack" <gnoack3000@gmail.com>
Cc: "Günther Noack" <gnoack@google.com>,
	"Shuah Khan" <shuah@kernel.org>,
	linux-security-module@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 11/27] selftests/landlock: Assert helper results that are used afterwards
Date: Fri, 4 Dec 2026 18:07:35 +0100	[thread overview]
Message-ID: <20261204.IeToh1phai9E@digikod.net> (raw)
In-Reply-To: <20261104-selftests-refactor-v2-11-c52f23f7ce33@gmail.com>

On Wed, Nov 04, 2026 at 10:08:57PM +0100, Günther Noack wrote:
> Some helpers check a result with EXPECT_*() and then use it:
> cap_get_proc() in _init_caps() and _change_cap(), and
> landlock_create_ruleset() in drop_access_rights(), create_domain() and
> create_fs_domain().  On failure they pass NULL or -1 to the next calls,
> which then fail with misleading messages.
> 
> Use ASSERT_*() for these checks, as create_scoped_domain() already does.
> 
> Signed-off-by: Günther Noack <gnoack3000@gmail.com>
> ---
>  tools/testing/selftests/landlock/common.h                    | 6 +++---
>  tools/testing/selftests/landlock/ptrace_test.c               | 2 +-
>  tools/testing/selftests/landlock/scoped_abstract_unix_test.c | 2 +-
>  3 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/testing/selftests/landlock/common.h b/tools/testing/selftests/landlock/common.h
> index 6c2aa913ff11..a662a68bee7b 100644
> --- a/tools/testing/selftests/landlock/common.h
> +++ b/tools/testing/selftests/landlock/common.h
> @@ -55,7 +55,7 @@ static void _init_caps(struct __test_metadata *const _metadata, bool drop_all)
>  		EXPECT_EQ(0, cap_set_secbits(noroot));
>  
>  	cap_p = cap_get_proc();
> -	EXPECT_NE(NULL, cap_p);
> +	ASSERT_NE(NULL, cap_p);
>  	EXPECT_NE(-1, cap_clear(cap_p));
>  	if (!drop_all) {
>  		EXPECT_NE(-1, cap_set_flag(cap_p, CAP_PERMITTED,
> @@ -91,7 +91,7 @@ static void _change_cap(struct __test_metadata *const _metadata,
>  	cap_t cap_p;
>  
>  	cap_p = cap_get_proc();
> -	EXPECT_NE(NULL, cap_p);
> +	ASSERT_NE(NULL, cap_p);

If _change_cap() aborts during cleanup_layout(), we never reach
audit_cleanup(). Could it return an error when cap_get_proc() fails,
so teardown can still try to clean up audit state?

Also, cap_stacking.two_layers can pass a negative FD to add_cap_rule()
before checking it. Could you check the FD before adding the rule and
keep the check for the FS-only branch?


>  	EXPECT_NE(-1, cap_set_flag(cap_p, flag, 1, &cap, value));
>  	EXPECT_NE(-1, cap_set_proc(cap_p))
>  	{
> @@ -227,7 +227,7 @@ drop_access_rights(struct __test_metadata *const _metadata,
>  
>  	ruleset_fd =
>  		landlock_create_ruleset(ruleset_attr, sizeof(*ruleset_attr), 0);
> -	EXPECT_LE(0, ruleset_fd)
> +	ASSERT_LE(0, ruleset_fd)
>  	{
>  		TH_LOG("Failed to create a ruleset: %s", strerror(errno));
>  	}
> diff --git a/tools/testing/selftests/landlock/ptrace_test.c b/tools/testing/selftests/landlock/ptrace_test.c
> index 10371c1830ad..b951889cd6ca 100644
> --- a/tools/testing/selftests/landlock/ptrace_test.c
> +++ b/tools/testing/selftests/landlock/ptrace_test.c
> @@ -37,7 +37,7 @@ static void create_domain(struct __test_metadata *const _metadata)
>  
>  	ruleset_fd =
>  		landlock_create_ruleset(&ruleset_attr, sizeof(ruleset_attr), 0);
> -	EXPECT_LE(0, ruleset_fd)
> +	ASSERT_LE(0, ruleset_fd)
>  	{
>  		TH_LOG("Failed to create a ruleset: %s", strerror(errno));
>  	}
> diff --git a/tools/testing/selftests/landlock/scoped_abstract_unix_test.c b/tools/testing/selftests/landlock/scoped_abstract_unix_test.c
> index 5e8224623780..55a1599819c8 100644
> --- a/tools/testing/selftests/landlock/scoped_abstract_unix_test.c
> +++ b/tools/testing/selftests/landlock/scoped_abstract_unix_test.c
> @@ -40,7 +40,7 @@ static void create_fs_domain(struct __test_metadata *const _metadata)
>  
>  	ruleset_fd =
>  		landlock_create_ruleset(&ruleset_attr, sizeof(ruleset_attr), 0);
> -	EXPECT_LE(0, ruleset_fd)
> +	ASSERT_LE(0, ruleset_fd)
>  	{
>  		TH_LOG("Failed to create a ruleset: %s", strerror(errno));
>  	}
> 
> -- 
> 2.56.0
> 
> 

  reply	other threads:[~2026-12-04 17:07 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 21:08 [PATCH v2 00/27] landlock: Selftest fixes and cleanups Günther Noack
2026-11-04 21:08 ` [PATCH v2 01/27] selftests/landlock: Propagate grandchild failures in unix_scoping Günther Noack
2026-11-04 21:08 ` [PATCH v2 02/27] selftests/landlock: Propagate EXPECT failures from forked children Günther Noack
2026-11-04 21:08 ` [PATCH v2 03/27] selftests/landlock: Check the thread result in audit.thread Günther Noack
2026-11-04 21:08 ` [PATCH v2 04/27] selftests/landlock: Zero-initialize the buffer in inconsistent_attr Günther Noack
2026-11-04 21:08 ` [PATCH v2 05/27] selftests/landlock: Fix the openat() success check in fs_bench Günther Noack
2026-11-04 21:08 ` [PATCH v2 06/27] selftests/landlock: Fix the reported clock tick rate " Günther Noack
2026-11-04 21:08 ` [PATCH v2 07/27] selftests/landlock: Fix the ruleset_fd check in empty_or_same_ruleset Günther Noack
2026-11-04 21:08 ` [PATCH v2 08/27] selftests/landlock: Handle a missing control message in recv_fd() Günther Noack
2026-11-04 21:08 ` [PATCH v2 09/27] selftests/landlock: Assert tracefs_extract_field() results that are used Günther Noack
2026-11-04 21:08 ` [PATCH v2 10/27] selftests/landlock: Assert audit initialization in fixture setups Günther Noack
2026-11-04 21:08 ` [PATCH v2 11/27] selftests/landlock: Assert helper results that are used afterwards Günther Noack
2026-12-04 17:07   ` Mickaël Salaün [this message]
2026-11-04 21:08 ` [PATCH v2 12/27] selftests/landlock: Assert audit_count_records() before using its result Günther Noack
2026-12-04 17:07   ` Mickaël Salaün
2026-11-04 21:08 ` [PATCH v2 13/27] selftests/landlock: Fix memory leak in audit_init_filter_exe() Günther Noack
2026-11-04 21:09 ` [PATCH v2 14/27] selftests/landlock: Make audit_message large enough for any exe filter Günther Noack
2026-11-04 21:09 ` [PATCH v2 15/27] selftests/landlock: Close leaked file descriptors Günther Noack
2026-11-04 21:09 ` [PATCH v2 16/27] selftests/landlock: Check errno for combined VERSION and ERRATA flags Günther Noack
2026-11-04 21:09 ` [PATCH v2 17/27] selftests/landlock: Fix SIGURG handler setup in scoped_signal_test Günther Noack
2026-11-04 21:09 ` [PATCH v2 18/27] selftests/landlock: Fix regex_escape() error handling in matches_log_fs_extra() Günther Noack
2026-11-04 21:09 ` [PATCH v2 19/27] selftests/landlock: Fix off-by-one in regex_escape() Günther Noack
2026-11-04 21:09 ` [PATCH v2 20/27] selftests/landlock: Fix the snprintf() error check in matches_log_fs_extra() Günther Noack
2026-11-04 21:09 ` [PATCH v2 21/27] selftests/landlock: Use _exit() in the named_pipe_ioctl child Günther Noack
2026-11-04 21:09 ` [PATCH v2 22/27] selftests/landlock: Fix messages and comments in helper programs Günther Noack
2026-11-04 21:09 ` [PATCH v2 23/27] selftests/landlock: Fix stale comments in common.h and audit.h Günther Noack
2026-11-04 21:09 ` [PATCH v2 24/27] selftests/landlock: Use ASSERT for syscall failures before errno checks Günther Noack
2026-12-04 17:07   ` Mickaël Salaün
2026-11-04 21:09 ` [PATCH v2 25/27] selftests/landlock: Assert WIFEXITED() before checking the exit status Günther Noack
2026-12-04 17:08   ` Mickaël Salaün
2026-11-04 21:09 ` [PATCH v2 26/27] selftests/landlock: Use EXPECT for closing FDs and stopping threads Günther Noack
2026-12-04 17:08   ` Mickaël Salaün
2026-11-04 21:09 ` [PATCH v2 27/27] selftests/landlock: Use EXPECT for checks that later steps do not need Günther Noack
2026-12-04 17:08   ` Mickaël Salaün
2026-12-04 17:07 ` [PATCH v2 00/27] landlock: Selftest fixes and cleanups Mickaël Salaün

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=20261204.IeToh1phai9E@digikod.net \
    --to=mic@digikod.net \
    --cc=gnoack3000@gmail.com \
    --cc=gnoack@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-security-module@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
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