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 <mic@digikod.net> 6 * Copyright © 2018-2020 ANSSI 7 */ 8 9 #ifndef _UAPI_LINUX_LANDLOCK_H 10 #define _UAPI_LINUX_LANDLOCK_H 11 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: it is a deny-by-default list that should 25 * contain as much Landlock access rights as possible. Indeed, all 26 * Landlock filesystem access rights that are not part of 27 * handled_access_fs are allowed. This is needed for backward 28 * compatibility reasons. One exception is the 29 * %LANDLOCK_ACCESS_FS_REFER access right, which is always implicitly 30 * handled, but must still be explicitly handled to add new rules with 31 * this access right. 32 */ 33 __u64 handled_access_fs; 34 }; 35 36 /* 37 * sys_landlock_create_ruleset() flags: 38 * 39 * - %LANDLOCK_CREATE_RULESET_VERSION: Get the highest supported Landlock ABI 40 * version. 41 */ 42 /* clang-format off */ 43 #define LANDLOCK_CREATE_RULESET_VERSION (1U << 0) 44 /* clang-format on */ 45 46 /** 47 * enum landlock_rule_type - Landlock rule type 48 * 49 * Argument of sys_landlock_add_rule(). 50 */ 51 enum landlock_rule_type { 52 /** 53 * @LANDLOCK_RULE_PATH_BENEATH: Type of a &struct 54 * landlock_path_beneath_attr . 55 */ 56 LANDLOCK_RULE_PATH_BENEATH = 1, 57 }; 58 59 /** 60 * struct landlock_path_beneath_attr - Path hierarchy definition 61 * 62 * Argument of sys_landlock_add_rule(). 63 */ 64 struct landlock_path_beneath_attr { 65 /** 66 * @allowed_access: Bitmask of allowed actions for this file hierarchy 67 * (cf. `Filesystem flags`_). 68 */ 69 __u64 allowed_access; 70 /** 71 * @parent_fd: File descriptor, preferably opened with ``O_PATH``, 72 * which identifies the parent directory of a file hierarchy, or just a 73 * file. 74 */ 75 __s32 parent_fd; 76 /* 77 * This struct is packed to avoid trailing reserved members. 78 * Cf. security/landlock/syscalls.c:build_check_abi() 79 */ 80 } __attribute__((packed)); 81 82 /** 83 * DOC: fs_access 84 * 85 * A set of actions on kernel objects may be defined by an attribute (e.g. 86 * &struct landlock_path_beneath_attr) including a bitmask of access. 87 * 88 * Filesystem flags 89 * ~~~~~~~~~~~~~~~~ 90 * 91 * These flags enable to restrict a sandboxed process to a set of actions on 92 * files and directories. Files or directories opened before the sandboxing 93 * are not subject to these restrictions. 94 * 95 * A file can only receive these access rights: 96 * 97 * - %LANDLOCK_ACCESS_FS_EXECUTE: Execute a file. 98 * - %LANDLOCK_ACCESS_FS_WRITE_FILE: Open a file with write access. Note that 99 * you might additionally need the %LANDLOCK_ACCESS_FS_TRUNCATE right in order 100 * to overwrite files with :manpage:`open(2)` using ``O_TRUNC`` or 101 * :manpage:`creat(2)`. 102 * - %LANDLOCK_ACCESS_FS_READ_FILE: Open a file with read access. 103 * - %LANDLOCK_ACCESS_FS_TRUNCATE: Truncate a file with :manpage:`truncate(2)`, 104 * :manpage:`ftruncate(2)`, :manpage:`creat(2)`, or :manpage:`open(2)` with 105 * ``O_TRUNC``. Whether an opened file can be truncated with 106 * :manpage:`ftruncate(2)` is determined during :manpage:`open(2)`, in the 107 * same way as read and write permissions are checked during 108 * :manpage:`open(2)` using %LANDLOCK_ACCESS_FS_READ_FILE and 109 * %LANDLOCK_ACCESS_FS_WRITE_FILE. This access right is available since the 110 * third version of the Landlock ABI. 111 * 112 * A directory can receive access rights related to files or directories. The 113 * following access right is applied to the directory itself, and the 114 * directories beneath it: 115 * 116 * - %LANDLOCK_ACCESS_FS_READ_DIR: Open a directory or list its content. 117 * 118 * However, the following access rights only apply to the content of a 119 * directory, not the directory itself: 120 * 121 * - %LANDLOCK_ACCESS_FS_REMOVE_DIR: Remove an empty directory or rename one. 122 * - %LANDLOCK_ACCESS_FS_REMOVE_FILE: Unlink (or rename) a file. 123 * - %LANDLOCK_ACCESS_FS_MAKE_CHAR: Create (or rename or link) a character 124 * device. 125 * - %LANDLOCK_ACCESS_FS_MAKE_DIR: Create (or rename) a directory. 126 * - %LANDLOCK_ACCESS_FS_MAKE_REG: Create (or rename or link) a regular file. 127 * - %LANDLOCK_ACCESS_FS_MAKE_SOCK: Create (or rename or link) a UNIX domain 128 * socket. 129 * - %LANDLOCK_ACCESS_FS_MAKE_FIFO: Create (or rename or link) a named pipe. 130 * - %LANDLOCK_ACCESS_FS_MAKE_BLOCK: Create (or rename or link) a block device. 131 * - %LANDLOCK_ACCESS_FS_MAKE_SYM: Create (or rename or link) a symbolic link. 132 * - %LANDLOCK_ACCESS_FS_REFER: Link or rename a file from or to a different 133 * directory (i.e. reparent a file hierarchy). This access right is 134 * available since the second version of the Landlock ABI. This is also the 135 * only access right which is always considered handled by any ruleset in 136 * such a way that reparenting a file hierarchy is always denied by default. 137 * To avoid privilege escalation, it is not enough to add a rule with this 138 * access right. When linking or renaming a file, the destination directory 139 * hierarchy must also always have the same or a superset of restrictions of 140 * the source hierarchy. If it is not the case, or if the domain doesn't 141 * handle this access right, such actions are denied by default with errno 142 * set to ``EXDEV``. Linking also requires a ``LANDLOCK_ACCESS_FS_MAKE_*`` 143 * access right on the destination directory, and renaming also requires a 144 * ``LANDLOCK_ACCESS_FS_REMOVE_*`` access right on the source's (file or 145 * directory) parent. Otherwise, such actions are denied with errno set to 146 * ``EACCES``. The ``EACCES`` errno prevails over ``EXDEV`` to let user space 147 * efficiently deal with an unrecoverable error. 148 * 149 * .. warning:: 150 * 151 * It is currently not possible to restrict some file-related actions 152 * accessible through these syscall families: :manpage:`chdir(2)`, 153 * :manpage:`stat(2)`, :manpage:`flock(2)`, :manpage:`chmod(2)`, 154 * :manpage:`chown(2)`, :manpage:`setxattr(2)`, :manpage:`utime(2)`, 155 * :manpage:`ioctl(2)`, :manpage:`fcntl(2)`, :manpage:`access(2)`. 156 * Future Landlock evolutions will enable to restrict them. 157 */ 158 /* clang-format off */ 159 #define LANDLOCK_ACCESS_FS_EXECUTE (1ULL << 0) 160 #define LANDLOCK_ACCESS_FS_WRITE_FILE (1ULL << 1) 161 #define LANDLOCK_ACCESS_FS_READ_FILE (1ULL << 2) 162 #define LANDLOCK_ACCESS_FS_READ_DIR (1ULL << 3) 163 #define LANDLOCK_ACCESS_FS_REMOVE_DIR (1ULL << 4) 164 #define LANDLOCK_ACCESS_FS_REMOVE_FILE (1ULL << 5) 165 #define LANDLOCK_ACCESS_FS_MAKE_CHAR (1ULL << 6) 166 #define LANDLOCK_ACCESS_FS_MAKE_DIR (1ULL << 7) 167 #define LANDLOCK_ACCESS_FS_MAKE_REG (1ULL << 8) 168 #define LANDLOCK_ACCESS_FS_MAKE_SOCK (1ULL << 9) 169 #define LANDLOCK_ACCESS_FS_MAKE_FIFO (1ULL << 10) 170 #define LANDLOCK_ACCESS_FS_MAKE_BLOCK (1ULL << 11) 171 #define LANDLOCK_ACCESS_FS_MAKE_SYM (1ULL << 12) 172 #define LANDLOCK_ACCESS_FS_REFER (1ULL << 13) 173 #define LANDLOCK_ACCESS_FS_TRUNCATE (1ULL << 14) 174 /* clang-format on */ 175 176 #endif /* _UAPI_LINUX_LANDLOCK_H */ 177