Skip to content

Commit cb2c7d1

Browse files
l0kodJames Morris
authored andcommitted
landlock: Support filesystem access-control
Using Landlock objects and ruleset, it is possible to tag inodes according to a process's domain. To enable an unprivileged process to express a file hierarchy, it first needs to open a directory (or a file) and pass this file descriptor to the kernel through landlock_add_rule(2). When checking if a file access request is allowed, we walk from the requested dentry to the real root, following the different mount layers. The access to each "tagged" inodes are collected according to their rule layer level, and ANDed to create access to the requested file hierarchy. This makes possible to identify a lot of files without tagging every inodes nor modifying the filesystem, while still following the view and understanding the user has from the filesystem. Add a new ARCH_EPHEMERAL_INODES for UML because it currently does not keep the same struct inodes for the same inodes whereas these inodes are in use. This commit adds a minimal set of supported filesystem access-control which doesn't enable to restrict all file-related actions. This is the result of multiple discussions to minimize the code of Landlock to ease review. Thanks to the Landlock design, extending this access-control without breaking user space will not be a problem. Moreover, seccomp filters can be used to restrict the use of syscall families which may not be currently handled by Landlock. Cc: Al Viro <[email protected]> Cc: Anton Ivanov <[email protected]> Cc: James Morris <[email protected]> Cc: Jann Horn <[email protected]> Cc: Jeff Dike <[email protected]> Cc: Kees Cook <[email protected]> Cc: Richard Weinberger <[email protected]> Cc: Serge E. Hallyn <[email protected]> Signed-off-by: Mickaël Salaün <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: James Morris <[email protected]>
1 parent 1aea780 commit cb2c7d1

File tree

12 files changed

+866
-2
lines changed

12 files changed

+866
-2
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10003,6 +10003,7 @@ L: [email protected]
1000310003
S: Supported
1000410004
W: https://landlock.io
1000510005
T: git https://github.com/landlock-lsm/linux.git
10006+
F: include/uapi/linux/landlock.h
1000610007
F: security/landlock/
1000710008
K: landlock
1000810009
K: LANDLOCK

arch/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,13 @@ config COMPAT_32BIT_TIME
10131013
config ARCH_NO_PREEMPT
10141014
bool
10151015

1016+
config ARCH_EPHEMERAL_INODES
1017+
def_bool n
1018+
help
1019+
An arch should select this symbol if it doesn't keep track of inode
1020+
instances on its own, but instead relies on something else (e.g. the
1021+
host kernel for an UML kernel).
1022+
10161023
config ARCH_SUPPORTS_RT
10171024
bool
10181025

arch/um/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ menu "UML-specific options"
55
config UML
66
bool
77
default y
8+
select ARCH_EPHEMERAL_INODES
89
select ARCH_HAS_KCOV
910
select ARCH_NO_PREEMPT
1011
select HAVE_ARCH_AUDITSYSCALL

include/uapi/linux/landlock.h

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2+
/*
3+
* Landlock - User space API
4+
*
5+
* Copyright © 2017-2020 Mickaël Salaün <[email protected]>
6+
* Copyright © 2018-2020 ANSSI
7+
*/
8+
9+
#ifndef _UAPI_LINUX_LANDLOCK_H
10+
#define _UAPI_LINUX_LANDLOCK_H
11+
12+
/**
13+
* DOC: fs_access
14+
*
15+
* A set of actions on kernel objects may be defined by an attribute (e.g.
16+
* &struct landlock_path_beneath_attr) including a bitmask of access.
17+
*
18+
* Filesystem flags
19+
* ~~~~~~~~~~~~~~~~
20+
*
21+
* These flags enable to restrict a sandboxed process to a set of actions on
22+
* files and directories. Files or directories opened before the sandboxing
23+
* are not subject to these restrictions.
24+
*
25+
* A file can only receive these access rights:
26+
*
27+
* - %LANDLOCK_ACCESS_FS_EXECUTE: Execute a file.
28+
* - %LANDLOCK_ACCESS_FS_WRITE_FILE: Open a file with write access.
29+
* - %LANDLOCK_ACCESS_FS_READ_FILE: Open a file with read access.
30+
*
31+
* A directory can receive access rights related to files or directories. The
32+
* following access right is applied to the directory itself, and the
33+
* directories beneath it:
34+
*
35+
* - %LANDLOCK_ACCESS_FS_READ_DIR: Open a directory or list its content.
36+
*
37+
* However, the following access rights only apply to the content of a
38+
* directory, not the directory itself:
39+
*
40+
* - %LANDLOCK_ACCESS_FS_REMOVE_DIR: Remove an empty directory or rename one.
41+
* - %LANDLOCK_ACCESS_FS_REMOVE_FILE: Unlink (or rename) a file.
42+
* - %LANDLOCK_ACCESS_FS_MAKE_CHAR: Create (or rename or link) a character
43+
* device.
44+
* - %LANDLOCK_ACCESS_FS_MAKE_DIR: Create (or rename) a directory.
45+
* - %LANDLOCK_ACCESS_FS_MAKE_REG: Create (or rename or link) a regular file.
46+
* - %LANDLOCK_ACCESS_FS_MAKE_SOCK: Create (or rename or link) a UNIX domain
47+
* socket.
48+
* - %LANDLOCK_ACCESS_FS_MAKE_FIFO: Create (or rename or link) a named pipe.
49+
* - %LANDLOCK_ACCESS_FS_MAKE_BLOCK: Create (or rename or link) a block device.
50+
* - %LANDLOCK_ACCESS_FS_MAKE_SYM: Create (or rename or link) a symbolic link.
51+
*
52+
* .. warning::
53+
*
54+
* It is currently not possible to restrict some file-related actions
55+
* accessible through these syscall families: :manpage:`chdir(2)`,
56+
* :manpage:`truncate(2)`, :manpage:`stat(2)`, :manpage:`flock(2)`,
57+
* :manpage:`chmod(2)`, :manpage:`chown(2)`, :manpage:`setxattr(2)`,
58+
* :manpage:`utime(2)`, :manpage:`ioctl(2)`, :manpage:`fcntl(2)`,
59+
* :manpage:`access(2)`.
60+
* Future Landlock evolutions will enable to restrict them.
61+
*/
62+
#define LANDLOCK_ACCESS_FS_EXECUTE (1ULL << 0)
63+
#define LANDLOCK_ACCESS_FS_WRITE_FILE (1ULL << 1)
64+
#define LANDLOCK_ACCESS_FS_READ_FILE (1ULL << 2)
65+
#define LANDLOCK_ACCESS_FS_READ_DIR (1ULL << 3)
66+
#define LANDLOCK_ACCESS_FS_REMOVE_DIR (1ULL << 4)
67+
#define LANDLOCK_ACCESS_FS_REMOVE_FILE (1ULL << 5)
68+
#define LANDLOCK_ACCESS_FS_MAKE_CHAR (1ULL << 6)
69+
#define LANDLOCK_ACCESS_FS_MAKE_DIR (1ULL << 7)
70+
#define LANDLOCK_ACCESS_FS_MAKE_REG (1ULL << 8)
71+
#define LANDLOCK_ACCESS_FS_MAKE_SOCK (1ULL << 9)
72+
#define LANDLOCK_ACCESS_FS_MAKE_FIFO (1ULL << 10)
73+
#define LANDLOCK_ACCESS_FS_MAKE_BLOCK (1ULL << 11)
74+
#define LANDLOCK_ACCESS_FS_MAKE_SYM (1ULL << 12)
75+
76+
#endif /* _UAPI_LINUX_LANDLOCK_H */

security/landlock/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
config SECURITY_LANDLOCK
44
bool "Landlock support"
5-
depends on SECURITY
5+
depends on SECURITY && !ARCH_EPHEMERAL_INODES
66
select SECURITY_PATH
77
help
88
Landlock is a sandboxing mechanism that enables processes to restrict

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

33
landlock-y := setup.o object.o ruleset.o \
4-
cred.o ptrace.o
4+
cred.o ptrace.o fs.o

0 commit comments

Comments
 (0)