| 3b70d866 | 18-Nov-2026 |
Mickaël Salaün <mic@digikod.net> |
selftests/landlock: Test namespace denial operations
The namespace trace tests cover creation and entry denials, but only creation exercises the quiet path. This leaves the new ENTER request tag un
selftests/landlock: Test namespace denial operations
The namespace trace tests cover creation and entry denials, but only creation exercises the quiet path. This leaves the new ENTER request tag untested through quiet selection and trace dispatch when audit logging is suppressed.
Add the missing quiet setns(2) case. Together with the existing cases, this exercises all four combinations of CREATE and ENTER with logged and quieted denials, including each exact namespace_op value.
Test coverage for security/landlock is 91.6% of 2894 lines according to LLVM 23.
Cc: Günther Noack <gnoack@google.com> Link: https://patch.msgid.link/20261118163254.2554413-4-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
show more ...
|
| a873f3c2 | 18-Nov-2026 |
Mickaël Salaün <mic@digikod.net> |
landlock: Distinguish namespace creation and entry denials
Landlock reports denied namespace creation and entry with the same internal request type. Before commit 08471914d6bb ("ns: allocate the na
landlock: Distinguish namespace creation and entry denials
Landlock reports denied namespace creation and entry with the same internal request type. Before commit 08471914d6bb ("ns: allocate the namespace id before the namespace_init hook"), denied creation carried ID zero and could be distinguished from entry by ID alone. That commit moved ID allocation before namespace_init(), so creation now carries the ID of an unreachable new namespace while entry carries the existing target ID. Namespace IDs are object context, not operation discriminators.
Split the request type into creation and entry. Keep the two namespace values together before capability; this renumbers the unreleased capability request in raw and typed trace context. Report namespace_op=create or namespace_op=enter immediately after blockers in namespace audit records and trace event text. Placing the operation before namespace_type and namespace_id lets consumers establish the semantics before interpreting the following namespace context, especially whether namespace_id is the creation-time value or identifies an existing entry target.
Keep namespace.use as the policy blocker: the new value only describes the semantic hook context and does not add a policy control.
Cc: Günther Noack <gnoack@google.com> Fixes: 15dd86021b57 ("landlock: Enforce namespace use restrictions") Link: https://patch.msgid.link/20261118163254.2554413-2-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
show more ...
|
| 10214398 | 18-Nov-2026 |
Mickaël Salaün <mic@digikod.net> |
selftests/landlock: Test PR_SET_SECUREBITS mediation
Test that Landlock denies and logs a privileged PR_SET_SECUREBITS change, now that the previous commit routes its CAP_SETPCAP check through the c
selftests/landlock: Test PR_SET_SECUREBITS mediation
Test that Landlock denies and logs a privileged PR_SET_SECUREBITS change, now that the previous commit routes its CAP_SETPCAP check through the capable hooks, and that an unprivileged change still succeeds. The domain deallocation record must then report exactly one denial, which proves that the unprivileged change was not denied, without relying on a no-record timeout.
The check-exec selftests already cover commoncap's securebits semantics. Without the previous commit, this test fails.
Cc: Christian Brauner <brauner@kernel.org> Cc: Günther Noack <gnoack@google.com> Cc: Paul Moore <paul@paul-moore.com> Cc: Serge Hallyn <serge@hallyn.com> Link: https://patch.msgid.link/20261118145431.2551578-3-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
show more ...
|
| 2c709fcc | 18-Nov-2026 |
Mickaël Salaün <mic@digikod.net> |
selftests/landlock: Test capability checks outside the capable hook
Test the commoncap checks that the previous commits make Landlock restrict: mapping below vm.mmap_min_addr (CAP_SYS_RAWIO) and add
selftests/landlock: Test capability checks outside the capable hook
Test the commoncap checks that the previous commits make Landlock restrict: mapping below vm.mmap_min_addr (CAP_SYS_RAWIO) and adding inheritable capabilities (CAP_SETPCAP). Each test checks that the operation needs the capability, then runs it with the capability in four variants: unsandboxed, denied, allowed and unhandled. The mmap_addr tests skip if the architecture rejects the low page before the hook (e.g. 32-bit ARM).
Audit tests check that these denials are logged, and that the admin reserve check and allowed uses are not. The admin reserve has no functional test because it depends on vm.overcommit_memory=2, a system-wide setting.
Add CAP_SETPCAP and CAP_SYS_RAWIO to the capabilities that the tests may raise.
Without the mmap_addr and capset fixes, their denied variants and the denial audit test fail.
Cc: Günther Noack <gnoack@google.com> Cc: Paul Moore <paul@paul-moore.com> Cc: Serge Hallyn <serge@hallyn.com> Acked-by: Serge Hallyn (AMD) <sergeh@kernel.org> Link: https://patch.msgid.link/20261118145217.2551053-6-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
show more ...
|
| 57493c3b | 13-Nov-2026 |
Günther Noack <gnoack3000@gmail.com> |
landlock: Clarify implicit handling of LANDLOCK_ACCESS_FS_REFER
The LANDLOCK_ACCESS_FS_REFER right is handled implicitly in a ruleset, but only if any other filesystem access right is declared as ha
landlock: Clarify implicit handling of LANDLOCK_ACCESS_FS_REFER
The LANDLOCK_ACCESS_FS_REFER right is handled implicitly in a ruleset, but only if any other filesystem access right is declared as handled in the given ruleset.
The old documentation was still a remnant from the times when filesystem access rights were the only access rights that existed in Landlock, but it became misleading when we introduced additional types of access rights.
Fixes: fff69fb03dde ("landlock: Support network rules with TCP bind and connect") Signed-off-by: Günther Noack <gnoack3000@gmail.com> Link: https://patch.msgid.link/20261113-b4-landlock-refer-nonfs-layer-v3-5-02d7e42bcdfd@gmail.com [mic: Reword _LANDLOCK_ACCESS_FS_INITIALLY_DENIED comment, fix comment wrapping, and include erratum 5 in userspace-api/landlock.rst] Signed-off-by: Mickaël Salaün <mic@digikod.net>
show more ...
|
| 8e4c736c | 26-Jun-2026 |
Wang Yan <wangyan01@kylinos.cn> |
selftests/landlock: Fix snprintf truncation checks in test files
Commit b566f7a4f0e4 ("selftests/landlock: Fix snprintf truncation checks in audit helpers") fixed the truncation detection in audit.h
selftests/landlock: Fix snprintf truncation checks in test files
Commit b566f7a4f0e4 ("selftests/landlock: Fix snprintf truncation checks in audit helpers") fixed the truncation detection in audit.h by changing the comparison from ">" to ">=" to correctly handle the edge case where snprintf returns a value equal to the buffer size.
However, the same pattern exists in ptrace_test.c, audit_test.c, and net_test.c and was not fixed. snprintf() returns the number of characters that would have been written, excluding the terminating NUL byte. When the output is truncated, this return value equals or exceeds the buffer size. The existing ">" check therefore fails to detect truncation when the return value equals the buffer size.
Fix these remaining instances to use ">=" for truncation detection, matching the fix in audit.h.
Fixes: 6a500b22971c ("selftests/landlock: Add tests for audit flags and domain IDs") Signed-off-by: Haofeng Li <lihaofeng@kylinos.cn> Signed-off-by: Wang Yan <wangyan01@kylinos.cn> Reviewed-by: Günther Noack <gnoack@google.com> Link: https://patch.msgid.link/20260626070016.61049-1-wangyan01@kylinos.cn Cc: stable@vger.kernel.org Signed-off-by: Mickaël Salaün <mic@digikod.net>
show more ...
|
| 5dcf1c85 | 14-Oct-2026 |
Mickaël Salaün <mic@digikod.net> |
selftests/landlock: Add capability restriction tests
Add tests to exercise LANDLOCK_PERMISSION_CAPABILITY_USE enforcement. A sandboxed process is denied a handled capability when no rule grants it,
selftests/landlock: Add capability restriction tests
Add tests to exercise LANDLOCK_PERMISSION_CAPABILITY_USE enforcement. A sandboxed process is denied a handled capability when no rule grants it, and an explicit rule restores it. Unknown capability values above CAP_LAST_CAP are accepted at rule-add time yet have no runtime effect, because deny-by-default still applies once the domain is enforced. Stacking tests cover the per-layer allow/deny combinations, including a layer that does not handle the permission, and invalid rule attributes return the expected errors.
Three tests exercise non-standard capability contexts: enforcing a domain via CAP_SYS_ADMIN authorization without no_new_privs, restricting capabilities gained through the kernel's user namespace ownership bypass (cap_capable_helper), and checking CAP_SYS_ADMIN against a descendant user namespace, with an unsandboxed positive control, to confirm the decision is independent of the target.
Audit tests verify denied and allowed capabilities, per-member quiet interactions, and CAP_OPT_NOAUDIT suppression. Trace tests cover accepted, rejected, and no-op rule adds, and normal, quiet, and CAP_OPT_NOAUDIT denials.
Test coverage for security/landlock is 91.8% of 2864 lines according to LLVM 22.
Cc: Christian Brauner <brauner@kernel.org> Cc: Günther Noack <gnoack@google.com> Cc: Paul Moore <paul@paul-moore.com> Cc: Serge E. Hallyn <serge@hallyn.com> Link: https://patch.msgid.link/20261014082718.1435842-7-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
show more ...
|
| de3a636c | 14-Oct-2026 |
Mickaël Salaün <mic@digikod.net> |
selftests/landlock: Add namespace restriction tests
Add tests covering LANDLOCK_PERMISSION_NAMESPACE_USE (namespace creation via unshare/clone and namespace entry via setns) and its interaction with
selftests/landlock: Add namespace restriction tests
Add tests covering LANDLOCK_PERMISSION_NAMESPACE_USE (namespace creation via unshare/clone and namespace entry via setns) and its interaction with LANDLOCK_PERMISSION_CAPABILITY_USE.
Rule validation covers the forward-compatibility contract: unknown CLONE_NEW* bits, including holes, upper-range bits and bit 63, are accepted at rule-add time yet have no runtime effect, because deny-by-default still applies once the domain is enforced. Empty masks, invalid permission selectors and non-zero flags are rejected.
Creation tests use FIXTURE_VARIANT to exercise all eight namespace types across allowed/denied and privileged/unprivileged combinations, so every type is shown to reach security_namespace_init(). Stacking tests cover the three per-layer allow/deny combinations that exercise distinct walker paths, and one domain handles both permissions at once.
Entry tests subject setns to the same type-based check through security_namespace_install(), across processes, and require both permissions to allow a non-user namespace.
The four open_tree(2) and fsmount(2) variants, anonymous and not, all create a mount namespace: they converge in security_namespace_init() with CLONE_NEWNS through different alloc_mnt_ns() paths. A CLONE_NEWUSER | CLONE_NEWUTS unshare under partial-allow rules shows that creation is sequential, so a denial on either type rolls the whole syscall back with EPERM.
Audit tests cover allowed and denied creation and entry, per-member quiet masks and the youngest-denying-layer rule. Trace tests cover handled permissions, successful and rejected rules, version history, namespace IDs, and quiet denials, including repeated and unknown-only effective no-ops.
Cc: Christian Brauner <brauner@kernel.org> Cc: Günther Noack <gnoack@google.com> Cc: Paul Moore <paul@paul-moore.com> Cc: Serge E. Hallyn <serge@hallyn.com> Link: https://patch.msgid.link/20261014082718.1435842-6-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
show more ...
|
| c8dcb172 | 18-Sep-2026 |
Mickaël Salaün <mic@digikod.net> |
selftests/landlock: Test network denial context
Network denial events now report the port from their one authoritative validated address through one signed field. Verify this value directly without
selftests/landlock: Test network denial context
Network denial events now report the port from their one authoritative validated address through one signed field. Verify this value directly without inferring a source or destination role.
Exercise a nonzero IPv4 TCP bind, an explicit-zero IPv4 UDP bind, a synthetic-zero IPv6 UDP autobind, and a family-only AF_UNSPEC UDP send. Require exactly one event with the exact policy blocker for each shape. The value -1 distinguishes a family-only address with no validated port from the two valid port-zero cases.
Test coverage for security/landlock is 91.6% of 2625 lines according to LLVM 22.
Cc: Günther Noack <gnoack@google.com> Cc: Steven Rostedt <rostedt@goodmis.org> Link: https://patch.msgid.link/20260918185036.608651-9-mic@digikod.net [mic: Add test coverage] Signed-off-by: Mickaël Salaün <mic@digikod.net>
show more ...
|
| c6dea91d | 18-Sep-2026 |
Mickaël Salaün <mic@digikod.net> |
selftests/landlock: Test filesystem denial blockers
Filesystem denial traces identify the policy change needed to allow a request, so require exact blocker values rather than merely nonempty output.
selftests/landlock: Test filesystem denial blockers
Filesystem denial traces identify the policy change needed to allow a request, so require exact blocker values rather than merely nonempty output. Pin a READ_DIR denial to exactly one event with blockers=read_dir. Pin a REFER-only mount denial to EPERM and exactly one event with blockers=change_topology.
The mount child retains CAP_SYS_ADMIN so Landlock is the only expected source of EPERM. This prevents a later capability failure from masking a Landlock regression; the trace-collecting parent remains unsandboxed.
Cc: Günther Noack <gnoack@google.com> Cc: Steven Rostedt <rostedt@goodmis.org> Link: https://patch.msgid.link/20260918185036.608651-8-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
show more ...
|
| 98b04ab0 | 18-Sep-2026 |
Mickaël Salaün <mic@digikod.net> |
landlock: Fix network denial trace context
Network denial events report source and destination ports reconstructed from audit data. Their zero values are ambiguous, and neither identifies the comple
landlock: Fix network denial trace context
Network denial events report source and destination ports reconstructed from audit data. Their zero values are ambiguous, and neither identifies the complete endpoint that Landlock checked.
Carry the checked sockaddr and its signed length in a private trace-only context. For an enabled event, validate the length and copy only the initialized prefix into zeroed local storage. This prevents a typed BPF program from reading uninitialized bytes while exposing the socket family, socket, address, and length.
Replace the source and destination trace-record fields with one signed port derived from the checked address. A value of -1 means that no port was checked, zero is a valid port, and positive values use host endianness. Bind blockers select the bind address; connect and send blockers select the destination.
Cc: Günther Noack <gnoack@google.com> Cc: Steven Rostedt <rostedt@goodmis.org> Fixes: 01ce260f5ccf ("landlock: Add landlock_deny_access_fs and landlock_deny_access_net") Link: https://patch.msgid.link/20260918185036.608651-5-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
show more ...
|
| d41d0021 | 07-Sep-2026 |
Mickaël Salaün <mic@digikod.net> |
landlock: Test trace path output boundaries
Use focused KUnit tests to exercise the renderer's internal boundary and composition contracts with synthetic scratch states, including both sibling-helpe
landlock: Test trace path output boundaries
Use focused KUnit tests to exercise the renderer's internal boundary and composition contracts with synthetic scratch states, including both sibling-helper evaluation orders. Check the exact output and reservation boundaries, including a four-byte octal escape accepted at exact capacity and rejected one byte short. Also verify an unchanged cursor on failure, that bracketed process names and embedded NUL bytes remain data, and that input ellipsis bytes are escaped rather than mistaken for the raw truncation marker.
The composition test requires generic trace output helpers. Enable CONFIG_FTRACE and CONFIG_SCHED_TRACER because the latter selects the otherwise-hidden CONFIG_TRACING support required by trace_print_flags_seq().
Use kselftests to exercise the complete tracefs path for both affected filesystem events. A valid path containing 2640 spaces exceeds the scratch output budget. Require its escaped prefix to end in the raw UTF-8 ellipsis while access_rights and blockers remain intact.
This division keeps the exact safety contract compiler-independent while proving that real tracepoints preserve their surrounding symbolic fields. The end-to-end assertions fail after a full fix revert with both GCC and Clang, while the composition KUnit test fails if the scratch reserve is removed.
Cc: Günther Noack <gnoack@google.com> Link: https://patch.msgid.link/20260907154401.124362-2-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
show more ...
|
| ac6d193d | 11-Aug-2026 |
Mickaël Salaün <mic@digikod.net> |
selftests/landlock: Add landlock_enforce_domain trace tests
Add trace tests for the landlock_enforce_domain event in trace_test.c, asserting field counts after the syscall returns rather than line o
selftests/landlock: Add landlock_enforce_domain trace tests
Add trace tests for the landlock_enforce_domain event in trace_test.c, asserting field counts after the syscall returns rather than line ordering across per-CPU buffers. They cover single-threaded and TSYNC enforcement (complete and process_wide set), a multi-threaded non-TSYNC process (process_wide clear), the single-threaded non-leader edge case, the flags-only path that creates no domain, and a thread-sync abort that emits create_domain and free_domain but no enforce_domain.
landlock_enforce_domain is added to the fixture enable path and every disable list so its zero-events assertions cannot be tripped by a stray enforcement event.
Test coverage for security/landlock is 91.6% of 2571 lines according to LLVM 22.
Cc: Günther Noack <gnoack@google.com> Cc: Tingmao Wang <m@maowtm.org> Link: https://patch.msgid.link/20260811094338.288094-19-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
show more ...
|
| aef2dd32 | 11-Aug-2026 |
Mickaël Salaün <mic@digikod.net> |
selftests/landlock: Add scope and ptrace tracepoint tests
Add trace tests for the landlock_deny_ptrace, landlock_deny_scope_signal, and landlock_deny_scope_abstract_unix_socket tracepoints, each pla
selftests/landlock: Add scope and ptrace tracepoint tests
Add trace tests for the landlock_deny_ptrace, landlock_deny_scope_signal, and landlock_deny_scope_abstract_unix_socket tracepoints, each placed alongside the functional tests for its subsystem, mirroring the audit test layout.
Each tracepoint is exercised by a fixture with three variants that pin both branches of the other-party domain field: denied against an unsandboxed other party (other-party domain ID 0), denied against a sandboxed other party (non-zero ID), and an allowed baseline that records no event. A second fixture per type exercises an alternate LSM hook that reaches the same tracepoint with the same other-party domain ID, since each denial type can be reached through more than one hook.
The datagram abstract-unix variant does not assert peer_pid, which is 0 for a datagram peer (no SO_PEERCRED); sun_path is the reliable peer identifier. The ptrace fixtures install a plain domain-creating ruleset rather than a dedicated flag, since ptrace denial relies on domain ancestry, not on a specific scoped flag. The fixtures unshare the mount namespace and remount / as MS_PRIVATE before mounting tracefs so the helper instance is visible only to the test process.
Cc: Günther Noack <gnoack@google.com> Cc: Tingmao Wang <m@maowtm.org> Link: https://patch.msgid.link/20260811094338.288094-18-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
show more ...
|
| 6e2df011 | 11-Aug-2026 |
Mickaël Salaün <mic@digikod.net> |
selftests/landlock: Add network tracepoint tests
Add network-specific trace tests, co-located with the existing audit fixture so each subsystem's functional, audit, and trace tests live together.
P
selftests/landlock: Add network tracepoint tests
Add network-specific trace tests, co-located with the existing audit fixture so each subsystem's functional, audit, and trace tests live together.
Parameterized fixtures verify the landlock_deny_access_net event: a bind or connect denied outside the ruleset emits exactly one event with the expected sport/dport, an allowed bind or connect emits none, and the unsandboxed baseline emits none. A separate fixture verifies the landlock_check_rule_net event on an allowed bind, anchoring its domain, access_request, port, and grants to exact values; only check_rule_fs had a dedicated field test before.
Port fields are read in host endianness, matching the landlock_net_port_attr.port UAPI convention, so the decimal comparisons also catch byte-order regressions in the tracepoint plumbing. IPv6 trace tests are intentionally elided: IPv6 hook dispatch shares the current_check_access_socket() path with IPv4 (covered by the audit tests), and the trace fields do not depend on address family.
Cc: Günther Noack <gnoack@google.com> Cc: Tingmao Wang <m@maowtm.org> Link: https://patch.msgid.link/20260811094338.288094-17-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
show more ...
|
| 30478db5 | 11-Aug-2026 |
Mickaël Salaün <mic@digikod.net> |
selftests/landlock: Add filesystem tracepoint tests
Add filesystem-specific trace tests in a dedicated file, following the audit-test pattern of living alongside each subsystem's functional tests.
selftests/landlock: Add filesystem tracepoint tests
Add filesystem-specific trace tests in a dedicated file, following the audit-test pattern of living alongside each subsystem's functional tests.
trace_fs_test.c verifies that the add_rule_fs, check_rule_fs, and deny_access_fs events fire with the correct fields on matching rules and denied accesses, that check_rule_fs does not fire for unhandled access types, and that no event fires without a sandbox. A denial covered by a quiet rule still emits a deny_access_fs event but with logged=0, the same suppression verdict audit applies; because that verdict must not depend on CONFIG_AUDIT, the test also runs under a tracepoints-only build.
Add trace_layout1 fixture tests in fs_test.c that reuse the layout1 hierarchy to verify the per-layer grants field: field values, multi-rule pathwalk short-circuit, request intersection, the optional truncate right surfacing in the request and grants, and an empty grants set from a rule that grants none of the requested rights.
Cc: Günther Noack <gnoack@google.com> Cc: Tingmao Wang <m@maowtm.org> Link: https://patch.msgid.link/20260811094338.288094-16-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
show more ...
|