Skip to content

landlock: Selftest fixes and cleanups

Günther Noack linux-kselftest linux-security-module lkml 2 versions – New

Get series with b4
b4 am [email protected] change-id 20261104-selftests-refactor-4741be042e4f

Versions newest first · linked by author and title

  1. v2 Latest27 patches 0 repliesNew
  2. v127 patches 1 replySuperseded

Changes in v2 from the cover letter

- Rebased onto master (v7.4-rc1-132-g05441d697f7f).
- Dropped the "Assisted-by: LLM" trailers (not required any more).
- Applied the same ASSERT/EXPECT rules to the test code that was added in the meantime (cap_test.c and ns_test.c, plus new checks in base_test.c and trace_test.c):
- "Assert tracefs_extract_field() results that are used": also the new handled_permissions check in trace.create_ruleset.
- "Assert audit initialization in fixture setups": also the cap_audit, ns_audit and ns_proc_open fixtures.
- "Assert audit_count_records() before using its result": also in cap_test.c and ns_test.c.
- "Use ASSERT for syscall failures before errno checks": also in cap_test.c and ns_test.c.
- "Use EXPECT for checks that later steps do not need": also the errno and WEXITSTATUS() checks in cap_test.c and ns_test.c, and the errno check in base_test.c's ruleset_with_unknown_permission.
- Dropped the note about depending on Wang Yan's snprintf() fix, which has landed as commit 8e4c736cffdd ("selftests/landlock: Fix snprintf truncation checks in test files").
- Link to v1: https://patch.msgid.link/[email protected]

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/27selftests/landlock: Propagate grandchild failures in unix_scopingtools/testing/selftests/landlock/scoped_abstract_unix_test.c+5 -00 replies
2/27selftests/landlock: Propagate EXPECT failures from forked childrentools/testing/selftests/landlock/audit_test.c tools/testing/selftests/landlock/scoped_signal_test.c+3 -30 replies
3/27selftests/landlock: Check the thread result in audit.threadtools/testing/selftests/landlock/audit_test.c+3 -10 replies
4/27selftests/landlock: Zero-initialize the buffer in inconsistent_attrtools/testing/selftests/landlock/base_test.c+1 -10 replies
5/27selftests/landlock: Fix the openat() success check in fs_benchtools/testing/selftests/landlock/fs_bench.c+1 -10 replies
6/27selftests/landlock: Fix the reported clock tick rate in fs_benchtools/testing/selftests/landlock/fs_bench.c+1 -20 replies
7/27selftests/landlock: Fix the ruleset_fd check in empty_or_same_rulesettools/testing/selftests/landlock/fs_test.c+1 -10 replies
8/27selftests/landlock: Handle a missing control message in recv_fd()tools/testing/selftests/landlock/common.h+1 -10 replies
9/27selftests/landlock: Assert tracefs_extract_field() results that are usedtools/testing/selftests/landlock/trace_test.c+11 -110 replies
10/27selftests/landlock: Assert audit initialization in fixture setupstools/testing/selftests/landlock/audit_test.c tools/testing/selftests/landlock/cap_test.c tools/testing/selftests/landlock/fs_test.c +4 more+13 -130 replies
11/27selftests/landlock: Assert helper results that are used afterwardstools/testing/selftests/landlock/common.h tools/testing/selftests/landlock/ptrace_test.c tools/testing/selftests/landlock/scoped_abstract_unix_test.c+5 -50 replies
12/27selftests/landlock: Assert audit_count_records() before using its resulttools/testing/selftests/landlock/audit_test.c tools/testing/selftests/landlock/cap_test.c tools/testing/selftests/landlock/fs_test.c +4 more+90 -900 replies
13/27selftests/landlock: Fix memory leak in audit_init_filter_exe()tools/testing/selftests/landlock/audit.h+3 -10 replies
14/27selftests/landlock: Make audit_message large enough for any exe filtertools/testing/selftests/landlock/audit.h+8 -10 replies
15/27selftests/landlock: Close leaked file descriptorstools/testing/selftests/landlock/audit_test.c tools/testing/selftests/landlock/base_test.c tools/testing/selftests/landlock/ptrace_test.c +2 more+21 -00 replies
16/27selftests/landlock: Check errno for combined VERSION and ERRATA flagstools/testing/selftests/landlock/base_test.c+2 -00 replies
17/27selftests/landlock: Fix SIGURG handler setup in scoped_signal_testtools/testing/selftests/landlock/scoped_signal_test.c+7 -70 replies
18/27selftests/landlock: Fix regex_escape() error handling in matches_log_fs_extra()tools/testing/selftests/landlock/common.h tools/testing/selftests/landlock/fs_test.c+19 -130 replies
19/27selftests/landlock: Fix off-by-one in regex_escape()tools/testing/selftests/landlock/common.h+1 -10 replies
20/27selftests/landlock: Fix the snprintf() error check in matches_log_fs_extra()tools/testing/selftests/landlock/fs_test.c+1 -10 replies
21/27selftests/landlock: Use _exit() in the named_pipe_ioctl childtools/testing/selftests/landlock/fs_test.c+1 -10 replies
22/27selftests/landlock: Fix messages and comments in helper programstools/testing/selftests/landlock/sandbox-and-launch.c tools/testing/selftests/landlock/wait-pipe-sandbox.c tools/testing/selftests/landlock/wait-pipe.c+12 -120 replies
23/27selftests/landlock: Fix stale comments in common.h and audit.htools/testing/selftests/landlock/audit.h tools/testing/selftests/landlock/common.h+4 -50 replies
24/27selftests/landlock: Use ASSERT for syscall failures before errno checkstools/testing/selftests/landlock/audit_test.c tools/testing/selftests/landlock/base_test.c tools/testing/selftests/landlock/cap_test.c +5 more+124 -1240 replies
25/27selftests/landlock: Assert WIFEXITED() before checking the exit statustools/testing/selftests/landlock/base_test.c tools/testing/selftests/landlock/fs_test.c tools/testing/selftests/landlock/net_test.c+13 -130 replies
26/27selftests/landlock: Use EXPECT for closing FDs and stopping threadstools/testing/selftests/landlock/base_test.c tools/testing/selftests/landlock/fs_test.c tools/testing/selftests/landlock/ptrace_test.c +3 more+99 -990 replies
27/27selftests/landlock: Use EXPECT for checks that later steps do not needtools/testing/selftests/landlock/audit_test.c tools/testing/selftests/landlock/base_test.c tools/testing/selftests/landlock/cap_test.c +6 more+602 -6020 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 00/27] landlock: Selftest fixes and cleanups

A collection of Landlock Selftest fixes
=======================================

This patch set is bundled together to be slightly less spammy, but the patches are mostly independent. The commits are ordered such that the simpler and more orthogonal patches come earlier.

The patch set is LLM-assisted (and that turned out to be very useful for spotting errors). Needless to say, I have verified all commits by hand, and reworked them where necessary.

The last few patches are a bit more cross-cutting and probably more prone to merge conflicts, as they correct cases where we have been using EXPECT and ASSERT in the wrong way (details in the commit messages). I believe that the rationale for each of these is reasonable, but I am happy to discuss.

Motivation
==========

LLMs (and humans ;-)) have an unfortunate tendency to pick up and replicate bad coding style patterns, so I hope that a broader cleanup of the test style will avoid this spreading further.

–Günther

---
Changes in v2:
- Rebased onto master (v7.4-rc1-132-g05441d697f7f).
- Dropped the "Assisted-by: LLM" trailers (not required any more).
- Applied the same ASSERT/EXPECT rules to the test code that was added in the meantime (cap_test.c and ns_test.c, plus new checks in base_test.c and trace_test.c):
- "Assert tracefs_extract_field() results that are used": also the new handled_permissions check in trace.create_ruleset.
- "Assert audit initialization in fixture setups": also the cap_audit, ns_audit and ns_proc_open fixtures.
- "Assert audit_count_records() before using its result": also in cap_test.c and ns_test.c.
- "Use ASSERT for syscall failures before errno checks": also in cap_test.c and ns_test.c.
- "Use EXPECT for checks that later steps do not need": also the errno and WEXITSTATUS() checks in cap_test.c and ns_test.c, and the errno check in base_test.c's ruleset_with_unknown_permission.
- Dropped the note about depending on Wang Yan's snprintf() fix, which has landed as commit 8e4c736cffdd ("selftests/landlock: Fix snprintf truncation checks in test files").
- Link to v1: https://patch.msgid.link/[email protected]

To: Mickaël Salaün <[email protected]>
To: Günther Noack <[email protected]>
To: Shuah Khan <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
Günther Noack (27):
selftests/landlock: Propagate grandchild failures in unix_scoping selftests/landlock: Propagate EXPECT failures from forked children selftests/landlock: Check the thread result in audit.thread selftests/landlock: Zero-initialize the buffer in inconsistent_attr selftests/landlock: Fix the openat() success check in fs_bench selftests/landlock: Fix the reported clock tick rate in fs_bench selftests/landlock: Fix the ruleset_fd check in empty_or_same_ruleset selftests/landlock: Handle a missing control message in recv_fd() selftests/landlock: Assert tracefs_extract_field() results that are used selftests/landlock: Assert audit initialization in fixture setups selftests/landlock: Assert helper results that are used afterwards selftests/landlock: Assert audit_count_records() before using its result selftests/landlock: Fix memory leak in audit_init_filter_exe() selftests/landlock: Make audit_message large enough for any exe filter selftests/landlock: Close leaked file descriptors selftests/landlock: Check errno for combined VERSION and ERRATA flags selftests/landlock: Fix SIGURG handler setup in scoped_signal_test selftests/landlock: Fix regex_escape() error handling in matches_log_fs_extra() selftests/landlock: Fix off-by-one in regex_escape() selftests/landlock: Fix the snprintf() error check in matches_log_fs_extra() selftests/landlock: Use _exit() in the named_pipe_ioctl child selftests/landlock: Fix messages and comments in helper programs selftests/landlock: Fix stale comments in common.h and audit.h selftests/landlock: Use ASSERT for syscall failures before errno checks selftests/landlock: Assert WIFEXITED() before checking the exit status selftests/landlock: Use EXPECT for closing FDs and stopping threads selftests/landlock: Use EXPECT for checks that later steps do not need

 tools/testing/selftests/landlock/audit.h           |   20 +-
 tools/testing/selftests/landlock/audit_test.c      |   56 +-
 tools/testing/selftests/landlock/base_test.c       |  192 +--
 tools/testing/selftests/landlock/cap_test.c        |   70 +-
 tools/testing/selftests/landlock/common.h          |   32 +-
 tools/testing/selftests/landlock/fs_bench.c        |    5 +-
 tools/testing/selftests/landlock/fs_test.c         | 1300 ++++++++++----------
 tools/testing/selftests/landlock/net_test.c        |   64 +-
 tools/testing/selftests/landlock/ns_test.c         |  124 +-
 tools/testing/selftests/landlock/ptrace_test.c     |   44 +-
 .../selftests/landlock/sandbox-and-launch.c        |    6 +-
 .../selftests/landlock/scoped_abstract_unix_test.c |   45 +-
 .../selftests/landlock/scoped_signal_test.c        |   23 +-
 tools/testing/selftests/landlock/scoped_test.c     |    2 +-
 tools/testing/selftests/landlock/trace_fs_test.c   |    8 +-
 tools/testing/selftests/landlock/trace_test.c      |   28 +-
 tools/testing/selftests/landlock/tsync_test.c      |   22 +-
 .../testing/selftests/landlock/wait-pipe-sandbox.c |   16 +-
 tools/testing/selftests/landlock/wait-pipe.c       |    2 +-
 19 files changed, 1051 insertions(+), 1008 deletions(-)

---
base-commit: 05441d697f7f9a927264f4058cbbc6a03dfcac9d
change-id: 20261104-selftests-refactor-4741be042e4f

Best regards,

Signature · 1 line
Günther Noack <[email protected]>