Skip to content

Add ABI v7: log flags - #120

Merged
l0kod merged 3 commits into
landlock-lsm:mainfrom
l0kod:abi-7
May 20, 2026
Merged

Add ABI v7: log flags#120
l0kod merged 3 commits into
landlock-lsm:mainfrom
l0kod:abi-7

Conversation

@l0kod

@l0kod l0kod commented Apr 10, 2026

Copy link
Copy Markdown
Member

Depends on #119

@lukehinds lukehinds left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very clean to me @l0kod , excited to see this land!

@l0kod

l0kod commented May 20, 2026

Copy link
Copy Markdown
Member Author

Depends on #124

@l0kod
l0kod force-pushed the abi-7 branch 2 times, most recently from f584c5c to 870e351 Compare May 20, 2026 16:09
l0kod added 3 commits May 20, 2026 19:23
Add ABI::V7 for restrict_self log flags introduced with Linux 6.15.

Add the syscall flag compatibility framework in a new flags module,
parallel to but simpler than the Access/TryCompat machinery.  Access
types operate on sets of rights with Full/Partial/No compat results;
syscall flags are set individually through boolean setters with binary
supported/not-supported results.

Add SyscallFlag (public sealed marker trait) and SyscallFlagExt
(pub(crate) extension: required default_value(), raw_bit(), since();
default try_compat() returning whether the non-default bit should be
applied).  Add Compatibility::try_compat_binary() factored from the No
branch of TryCompat::try_compat() for the shared compat level dispatch.
Add SyscallFlagError<F: SyscallFlag> generic error carrying the flag
identity and boolean value.

Add RestrictSelfFlag (public enum, no #[bitflags], clean names without
*Off/*On suffixes).  RestrictSelfFlag is not an access right and does
not implement the Access trait, which would pull in the
AccessError/CompatError generic hierarchy.  The polarity mapping (e.g.,
log_same_exec(false) maps to LANDLOCK_RESTRICT_SELF_LOG_SAME_EXEC_OFF)
is encoded directly in raw_bit() (which returns the OFF/ON UAPI
constant) and decoded by is_set() when reporting the effective state.
Each flag declares its minimum ABI via since() for per-variant compat
gating.

The public API is three boolean methods: log_subdomains() on the
RestrictSelfAttr trait, and log_same_exec()/log_new_exec() on
RulesetCreatedAttr (which gains RestrictSelfAttr as a supertrait so
domain-bearing builders share the subdomain setter).  The
RestrictSelfFlagsState plumbing trait follows the same private module
pattern as compat::private::OptionCompatLevelMut.

Update RulesetCreated to store requested and actual restrict_self flags
as raw u32 bitmasks, pass actual flags to the landlock_restrict_self()
syscall, and report the effective state on RestrictionStatus through
three new public fields (log_same_exec, log_new_exec, log_subdomains).

Append ABI::V7 to all from_all() match arms for AccessFs, AccessNet,
Scope, and From<ABI> for BitFlags<Erratum>.  Update errata
not_backported_yet() and errata_up_to_date test for ABI v7.

Re-add LANDLOCK_CRATE_TEST_ABI=7 to the MSRV CI job (previously
removed because ABI v7 was not yet defined).

Signed-off-by: Mickaël Salaün <mic@digikod.net>
Add the RestrictSelf builder for calling landlock_restrict_self(-1,
flags) without creating a Landlock domain.  This enables setting
restrict_self flags (e.g., muting subdomain audit logs) without creating
a ruleset.

RestrictSelf uses the same RestrictSelfAttr trait as RulesetCreated,
sharing the log_subdomains() setter, and adds an inherent
no_new_privs(self, bool) -> Self method mirroring
RulesetCreatedAttr::no_new_privs() for the domain-less case.  It
implements Compatible for per-flag compat level control.

RestrictSelf::apply() calls prctl(PR_SET_NO_NEW_PRIVS, 1) by default
since the kernel requires no_new_privs (or CAP_SYS_ADMIN) for
landlock_restrict_self(2) even with ruleset_fd == -1; use
no_new_privs(false) to opt out.  Both apply() and
RulesetCreated::restrict_self() share the try_set_no_new_privs() helper
extracted in the previous commit.

apply() returns a RestrictSelfStatus reporting LandlockStatus,
no_new_privs, and the log_subdomains flag state.  Skips the
landlock_restrict_self() syscall when no flags are enforceable.

The integration test helper check_restrict_self_support() mirrors the
check_ruleset_support() signature (partial, full).  A new
check_support() helper, generic over the builder and status types,
factors out the iteration, thread::spawn, and can_emulate dispatch
shared by both helpers.

Signed-off-by: Mickaël Salaün <mic@digikod.net>
Bump the example to ABI v7 and add LL_FORCE_LOG environment variable
support to enable audit logging of denied accesses after execve(2),
matching the kernel's sandboxer example.  The setter is wrapped in
HardRequirement so that LL_FORCE_LOG=1 fails loudly on kernels without
the feature.

Remove LL_SCOPED and LL_FORCE_LOG from the child process environment
before exec, matching the kernel's unsetenv() calls.

Fix a pre-existing bug: LL_SCOPED was not being removed from the child
process environment, leaking the variable to spawned commands.

Signed-off-by: Mickaël Salaün <mic@digikod.net>
@l0kod
l0kod merged commit 43128a1 into landlock-lsm:main May 20, 2026
41 checks passed
@l0kod
l0kod deleted the abi-7 branch May 20, 2026 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants