sys_landlock_add_rule(9)
π sys_landlock_add_rule(9) β the Kernel API Manual bestie edition β¨
okay so before we even start: this is a page from the Kernel API Manual, section 9, and it's all about sys_landlock_add_rule. sit down, grab a strawberry drink π, and let's get into it because this syscall is genuinely iconic.
πΈ NAME πΈ
sys_landlock_add_rule β bestie, it adds a new rule to a ruleset. that's the whole vibe. π
β¨ SYNOPSIS β¨
long sys_landlock_add_rule (const int ruleset_fd , const enum
landlock_rule_type rule_type , const void __user *const rule_attr ,
const __u32 flags );
look at that signature. she's long, she's got const everywhere, she's that girl. π
π«Ά ARGUMENTS π«Ά
ruleset_fdβ the file descriptor tied to the ruleset that should be extended with the new rule. it's literally the ruleset you're adding to, no cap.rule_typeβ identifies the structure type thatrule_attris pointing at. the options areLANDLOCK_RULE_PATH_BENEATHorLANDLOCK_RULE_NET_PORT. choose wisely, queen π.rule_attrβ pointer to a rule (and it has to match therule_type, obviously). the actual content β¨.flagsβ must be0orLANDLOCK_ADD_RULE_QUIET. that's it. that's the whole list. don't get creative π.
π₯ DESCRIPTION π₯
so this system call enables you to define a new rule and add it to an existing ruleset. that's the main character energy of the whole page. π
and then we get into the error lore, which is honestly a lot, so buckle up:
EOPNOTSUPPβ Landlock is supported by the kernel but disabled at boot time. so the vibes are there, the feature just isn't turned on π.EAFNOSUPPORTβrule_typeisLANDLOCK_RULE_NET_PORTbut TCP/IP is not supported by the running kernel. wrong kernel for that net port fantasy, sorry.EINVALβflagsis not valid. you tried it. it didn't work.EINVALβ the rule accesses are inconsistent (i.e.landlock_path_beneath_attr.allowed_accessorlandlock_net_port_attr.allowed_accessis not a subset of the ruleset handled accesses). math is not mathing.EINVALβlandlock_net_port_attr.portis greater than65535. that port is out of range, bestie π.EINVALβLANDLOCK_ADD_RULE_QUIETis passed but the ruleset has no quiet access bits set for the corresponding rule type. you asked for quiet mode on a ruleset that isn't serving quiet mode.ENOMSGβ empty accesses (e.g.landlock_path_beneath_attr.allowed_accessis0and no flags). nothing inside. empty. void. πEBADFβruleset_fdis not a file descriptor for the current thread, or a member ofrule_attris not a file descriptor as expected.EBADFDβruleset_fdis not a ruleset file descriptor, or a member ofrule_attris not the expected file descriptor type. yes,EBADFandEBADFDare two different things, and yes, they will both humble you.EPERMβruleset_fdhas no write access to the underlying ruleset. no write access, no entry π«.EFAULTβrule_attrwas not a valid address. the pointer said "trust me" and lied.
also, there's this kernel-doc bit that's just sitting here being all mysterious:
.. kernel-doc:: include/uapi/linux/landlock.h :identifiers:
landlock_add_rule_flags
that's for landlock_add_rule_flags. iconic of it to just appear with no further comment. π¦
β RETURN β
0 on success, or -errno on failure. possible returned errors are: (yes, they're the ones listed up above in DESCRIPTION, go scroll back, i'll wait π§)
π SEE ALSO π
- Kernel file
./security/landlock/syscalls.ccopy_min_struct_from_user(9) sys_landlock_create_ruleset(9)sys_landlock_restrict_self(9)
the whole landlock friend group honestly. go read them too, they're all linked. π
okay that's the page!! and before you go β the source is from ./security/landlock, dated October 2026, and the whole thing is filed under sys_landlock_add_rule(9). so there you have it: sourced, dated, and absolutely slaying. mwah πβ¨π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms