Skip to content

Commit 265885d

Browse files
l0kodJames Morris
authored andcommitted
landlock: Add syscall implementations
These 3 system calls are designed to be used by unprivileged processes to sandbox themselves: * landlock_create_ruleset(2): Creates a ruleset and returns its file descriptor. * landlock_add_rule(2): Adds a rule (e.g. file hierarchy access) to a ruleset, identified by the dedicated file descriptor. * landlock_restrict_self(2): Enforces a ruleset on the calling thread and its future children (similar to seccomp). This syscall has the same usage restrictions as seccomp(2): the caller must have the no_new_privs attribute set or have CAP_SYS_ADMIN in the current user namespace. All these syscalls have a "flags" argument (not currently used) to enable extensibility. Here are the motivations for these new syscalls: * A sandboxed process may not have access to file systems, including /dev, /sys or /proc, but it should still be able to add more restrictions to itself. * Neither prctl(2) nor seccomp(2) (which was used in a previous version) fit well with the current definition of a Landlock security policy. All passed structs (attributes) are checked at build time to ensure that they don't contain holes and that they are aligned the same way for each architecture. See the user and kernel documentation for more details (provided by a following commit): * Documentation/userspace-api/landlock.rst * Documentation/security/landlock.rst Cc: Arnd Bergmann <[email protected]> Cc: James Morris <[email protected]> Cc: Jann Horn <[email protected]> Cc: Kees Cook <[email protected]> Signed-off-by: Mickaël Salaün <[email protected]> Acked-by: Serge Hallyn <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: James Morris <[email protected]>
1 parent a49f4f8 commit 265885d

File tree

5 files changed

+508
-1
lines changed

5 files changed

+508
-1
lines changed

include/linux/syscalls.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ struct io_uring_params;
6969
struct clone_args;
7070
struct open_how;
7171
struct mount_attr;
72+
struct landlock_ruleset_attr;
73+
enum landlock_rule_type;
7274

7375
#include <linux/types.h>
7476
#include <linux/aio_abi.h>
@@ -1041,6 +1043,11 @@ asmlinkage long sys_pidfd_send_signal(int pidfd, int sig,
10411043
siginfo_t __user *info,
10421044
unsigned int flags);
10431045
asmlinkage long sys_pidfd_getfd(int pidfd, int fd, unsigned int flags);
1046+
asmlinkage long sys_landlock_create_ruleset(const struct landlock_ruleset_attr __user *attr,
1047+
size_t size, __u32 flags);
1048+
asmlinkage long sys_landlock_add_rule(int ruleset_fd, enum landlock_rule_type rule_type,
1049+
const void __user *rule_attr, __u32 flags);
1050+
asmlinkage long sys_landlock_restrict_self(int ruleset_fd, __u32 flags);
10441051

10451052
/*
10461053
* Architecture-specific system calls

include/uapi/linux/landlock.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,59 @@
99
#ifndef _UAPI_LINUX_LANDLOCK_H
1010
#define _UAPI_LINUX_LANDLOCK_H
1111

12+
#include <linux/types.h>
13+
14+
/**
15+
* struct landlock_ruleset_attr - Ruleset definition
16+
*
17+
* Argument of sys_landlock_create_ruleset(). This structure can grow in
18+
* future versions.
19+
*/
20+
struct landlock_ruleset_attr {
21+
/**
22+
* @handled_access_fs: Bitmask of actions (cf. `Filesystem flags`_)
23+
* that is handled by this ruleset and should then be forbidden if no
24+
* rule explicitly allow them. This is needed for backward
25+
* compatibility reasons.
26+
*/
27+
__u64 handled_access_fs;
28+
};
29+
30+
/**
31+
* enum landlock_rule_type - Landlock rule type
32+
*
33+
* Argument of sys_landlock_add_rule().
34+
*/
35+
enum landlock_rule_type {
36+
/**
37+
* @LANDLOCK_RULE_PATH_BENEATH: Type of a &struct
38+
* landlock_path_beneath_attr .
39+
*/
40+
LANDLOCK_RULE_PATH_BENEATH = 1,
41+
};
42+
43+
/**
44+
* struct landlock_path_beneath_attr - Path hierarchy definition
45+
*
46+
* Argument of sys_landlock_add_rule().
47+
*/
48+
struct landlock_path_beneath_attr {
49+
/**
50+
* @allowed_access: Bitmask of allowed actions for this file hierarchy
51+
* (cf. `Filesystem flags`_).
52+
*/
53+
__u64 allowed_access;
54+
/**
55+
* @parent_fd: File descriptor, open with ``O_PATH``, which identifies
56+
* the parent directory of a file hierarchy, or just a file.
57+
*/
58+
__s32 parent_fd;
59+
/*
60+
* This struct is packed to avoid trailing reserved members.
61+
* Cf. security/landlock/syscalls.c:build_check_abi()
62+
*/
63+
} __attribute__((packed));
64+
1265
/**
1366
* DOC: fs_access
1467
*

kernel/sys_ni.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ COND_SYSCALL(request_key);
266266
COND_SYSCALL(keyctl);
267267
COND_SYSCALL_COMPAT(keyctl);
268268

269+
/* security/landlock/syscalls.c */
270+
COND_SYSCALL(landlock_create_ruleset);
271+
COND_SYSCALL(landlock_add_rule);
272+
COND_SYSCALL(landlock_restrict_self);
273+
269274
/* arch/example/kernel/sys_example.c */
270275

271276
/* mm/fadvise.c */

security/landlock/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
obj-$(CONFIG_SECURITY_LANDLOCK) := landlock.o
22

3-
landlock-y := setup.o object.o ruleset.o \
3+
landlock-y := setup.o syscalls.o object.o ruleset.o \
44
cred.o ptrace.o fs.o

0 commit comments

Comments
 (0)