# Re: \[PATCH v2 24/27\] selftests/landlock: Use ASSERT for syscall failures before errno checks

- From: sashiko-bot@kernel.org
- Date: 2026-11-04 21:21:55 
- List: linux-security-module
- Page: https://ratatoskr.run/linux-security-module/2026/11/17864936
- Thread: https://ratatoskr.run/linux-security-module/2026/11/17864489/t.md

```text
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] selftests/landlock: ASSERT_EQ() after PTRACE_ATTACH skips detach and stops peer
--

commit 9f0b61a144fcc6c9f95be698e621be787a64a44b
Author: Günther Noack [ref]

selftests/landlock: Use ASSERT for syscall failures before errno checks

This commit replaces EXPECT_EQ() with ASSERT_EQ() for syscall return value
checks in Landlock selftests so tests abort before checking errno when a
syscall expected to fail unexpectedly succeeds.

> diff --git a/tools/testing/selftests/landlock/ptrace_test.c b/tools/testing/selftests/landlock/ptrace_test.c
> index 4fd2b440aa455..ea8e4be6659e9 100644
> --- a/tools/testing/selftests/landlock/ptrace_test.c
> +++ b/tools/testing/selftests/landlock/ptrace_test.c
> @@ -204,7 +204,7 @@ TEST_F(scoped_domains, trace)
>  		if (can_trace_parent) {
>  			EXPECT_EQ(0, ret);
>  		} else {
> -			EXPECT_EQ(-1, ret);
> +			ASSERT_EQ(-1, ret);
>  			EXPECT_EQ(EPERM, errno);
>  		}
>  		if (ret == 0) {

[ ... ]

> @@ -276,7 +276,7 @@ TEST_F(scoped_domains, trace)
>  	if (can_trace_child) {
>  		EXPECT_EQ(0, ret);
>  	} else {
> -		EXPECT_EQ(-1, ret);
> +		ASSERT_EQ(-1, ret);
>  		EXPECT_EQ(EPERM, errno);
>  	}

[Severity: Medium]
As reported by Sashiko on v1 [1], in TEST_F(scoped_domains, trace) in
tools/testing/selftests/landlock/ptrace_test.c, if ptrace(PTRACE_ATTACH, ...)
unexpectedly succeeds (ret == 0) when can_trace_parent or can_trace_child is
false, the target process is sent SIGSTOP by the kernel.

Previously, with EXPECT_EQ(-1, ret), execution continued into the following
cleanup block even on an unexpected attach:

	if (ret == 0) {
		ASSERT_EQ(parent, waitpid(parent, &status, 0));
		ASSERT_EQ(1, WIFSTOPPED(status));
		ASSERT_EQ(0, ptrace(PTRACE_DETACH, parent, NULL, 0));
	}

which waited for the stop and detached the tracee cleanly.

With ASSERT_EQ(-1, ret), doesn't an unexpected attach success abort the
tracer before reaching the if (ret == 0) block, leaving the tracee in
TASK_STOPPED from the pending SIGSTOP (and causing the parent test process to
hang until the kselftest harness timeout when the child attaches to the
parent)?

[1] https://lore.kernel.org/r/20261008142604.39107-26-gnoack3000@gmail.com

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261104-selftests-refactor-v2-0-c52f23f7ce33@gmail.com?part=24
```
