1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux 1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 /* 2 /* 3 * Landlock - User space API 3 * Landlock - User space API 4 * 4 * 5 * Copyright © 2017-2020 Mickaël Salaün <mi 5 * Copyright © 2017-2020 Mickaël Salaün <mic@digikod.net> 6 * Copyright © 2018-2020 ANSSI 6 * Copyright © 2018-2020 ANSSI 7 */ 7 */ 8 8 9 #ifndef _UAPI_LINUX_LANDLOCK_H 9 #ifndef _UAPI_LINUX_LANDLOCK_H 10 #define _UAPI_LINUX_LANDLOCK_H 10 #define _UAPI_LINUX_LANDLOCK_H 11 11 12 #include <linux/types.h> 12 #include <linux/types.h> 13 13 14 /** 14 /** 15 * struct landlock_ruleset_attr - Ruleset defi !! 15 * struct landlock_ruleset_attr - Ruleset definition 16 * 16 * 17 * Argument of sys_landlock_create_ruleset(). !! 17 * Argument of sys_landlock_create_ruleset(). This structure can grow in 18 * !! 18 * future versions. 19 * This structure defines a set of *handled ac << 20 * different object types, which should be den << 21 * enacted. Vice versa, access rights that ar << 22 * not going to be denied by this ruleset when << 23 * << 24 * For historical reasons, the %LANDLOCK_ACCES << 25 * by default, even when its bit is not set in << 26 * add new rules with this access right, the b << 27 * (cf. `Filesystem flags`_). << 28 * << 29 * The explicit listing of *handled access rig << 30 * compatibility reasons. In most use cases, << 31 * *handle* a wide range or all access rights << 32 * (and that they have tested with a kernel th << 33 * << 34 * This structure can grow in future Landlock << 35 */ 19 */ 36 struct landlock_ruleset_attr { 20 struct landlock_ruleset_attr { 37 /** 21 /** 38 * @handled_access_fs: Bitmask of hand !! 22 * @handled_access_fs: Bitmask of actions (cf. `Filesystem flags`_) 39 * (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. 40 */ 32 */ 41 __u64 handled_access_fs; 33 __u64 handled_access_fs; 42 /** 34 /** 43 * @handled_access_net: Bitmask of han !! 35 * @handled_access_net: Bitmask of actions (cf. `Network flags`_) 44 * flags`_). !! 36 * that is handled by this ruleset and should then be forbidden if no >> 37 * rule explicitly allow them. 45 */ 38 */ 46 __u64 handled_access_net; 39 __u64 handled_access_net; 47 }; 40 }; 48 41 49 /* 42 /* 50 * sys_landlock_create_ruleset() flags: 43 * sys_landlock_create_ruleset() flags: 51 * 44 * 52 * - %LANDLOCK_CREATE_RULESET_VERSION: Get the 45 * - %LANDLOCK_CREATE_RULESET_VERSION: Get the highest supported Landlock ABI 53 * version. 46 * version. 54 */ 47 */ 55 /* clang-format off */ 48 /* clang-format off */ 56 #define LANDLOCK_CREATE_RULESET_VERSION 49 #define LANDLOCK_CREATE_RULESET_VERSION (1U << 0) 57 /* clang-format on */ 50 /* clang-format on */ 58 51 59 /** 52 /** 60 * enum landlock_rule_type - Landlock rule typ 53 * enum landlock_rule_type - Landlock rule type 61 * 54 * 62 * Argument of sys_landlock_add_rule(). 55 * Argument of sys_landlock_add_rule(). 63 */ 56 */ 64 enum landlock_rule_type { 57 enum landlock_rule_type { 65 /** 58 /** 66 * @LANDLOCK_RULE_PATH_BENEATH: Type o 59 * @LANDLOCK_RULE_PATH_BENEATH: Type of a &struct 67 * landlock_path_beneath_attr . 60 * landlock_path_beneath_attr . 68 */ 61 */ 69 LANDLOCK_RULE_PATH_BENEATH = 1, 62 LANDLOCK_RULE_PATH_BENEATH = 1, 70 /** 63 /** 71 * @LANDLOCK_RULE_NET_PORT: Type of a 64 * @LANDLOCK_RULE_NET_PORT: Type of a &struct 72 * landlock_net_port_attr . 65 * landlock_net_port_attr . 73 */ 66 */ 74 LANDLOCK_RULE_NET_PORT, 67 LANDLOCK_RULE_NET_PORT, 75 }; 68 }; 76 69 77 /** 70 /** 78 * struct landlock_path_beneath_attr - Path hi 71 * struct landlock_path_beneath_attr - Path hierarchy definition 79 * 72 * 80 * Argument of sys_landlock_add_rule(). 73 * Argument of sys_landlock_add_rule(). 81 */ 74 */ 82 struct landlock_path_beneath_attr { 75 struct landlock_path_beneath_attr { 83 /** 76 /** 84 * @allowed_access: Bitmask of allowed 77 * @allowed_access: Bitmask of allowed actions for this file hierarchy 85 * (cf. `Filesystem flags`_). 78 * (cf. `Filesystem flags`_). 86 */ 79 */ 87 __u64 allowed_access; 80 __u64 allowed_access; 88 /** 81 /** 89 * @parent_fd: File descriptor, prefer 82 * @parent_fd: File descriptor, preferably opened with ``O_PATH``, 90 * which identifies the parent directo 83 * which identifies the parent directory of a file hierarchy, or just a 91 * file. 84 * file. 92 */ 85 */ 93 __s32 parent_fd; 86 __s32 parent_fd; 94 /* 87 /* 95 * This struct is packed to avoid trai 88 * This struct is packed to avoid trailing reserved members. 96 * Cf. security/landlock/syscalls.c:bu 89 * Cf. security/landlock/syscalls.c:build_check_abi() 97 */ 90 */ 98 } __attribute__((packed)); 91 } __attribute__((packed)); 99 92 100 /** 93 /** 101 * struct landlock_net_port_attr - Network por 94 * struct landlock_net_port_attr - Network port definition 102 * 95 * 103 * Argument of sys_landlock_add_rule(). 96 * Argument of sys_landlock_add_rule(). 104 */ 97 */ 105 struct landlock_net_port_attr { 98 struct landlock_net_port_attr { 106 /** 99 /** 107 * @allowed_access: Bitmask of allowed !! 100 * @allowed_access: Bitmask of allowed access network for a port 108 * (cf. `Network flags`_). 101 * (cf. `Network flags`_). 109 */ 102 */ 110 __u64 allowed_access; 103 __u64 allowed_access; 111 /** 104 /** 112 * @port: Network port in host endiann 105 * @port: Network port in host endianness. 113 * 106 * 114 * It should be noted that port 0 pass !! 107 * It should be noted that port 0 passed to :manpage:`bind(2)` will 115 * to an available port from the ephem !! 108 * bind to an available port from a specific port range. This can be 116 * configured with the ``/proc/sys/net !! 109 * configured thanks to the ``/proc/sys/net/ipv4/ip_local_port_range`` 117 * (also used for IPv6). !! 110 * sysctl (also used for IPv6). A Landlock rule with port 0 and the 118 * !! 111 * ``LANDLOCK_ACCESS_NET_BIND_TCP`` right means that requesting to bind 119 * A Landlock rule with port 0 and the !! 112 * on port 0 is allowed and it will automatically translate to binding 120 * right means that requesting to bind !! 113 * on the related port range. 121 * automatically translate to binding << 122 */ 114 */ 123 __u64 port; 115 __u64 port; 124 }; 116 }; 125 117 126 /** 118 /** 127 * DOC: fs_access 119 * DOC: fs_access 128 * 120 * 129 * A set of actions on kernel objects may be d 121 * A set of actions on kernel objects may be defined by an attribute (e.g. 130 * &struct landlock_path_beneath_attr) includi 122 * &struct landlock_path_beneath_attr) including a bitmask of access. 131 * 123 * 132 * Filesystem flags 124 * Filesystem flags 133 * ~~~~~~~~~~~~~~~~ 125 * ~~~~~~~~~~~~~~~~ 134 * 126 * 135 * These flags enable to restrict a sandboxed 127 * These flags enable to restrict a sandboxed process to a set of actions on 136 * files and directories. Files or directorie 128 * files and directories. Files or directories opened before the sandboxing 137 * are not subject to these restrictions. 129 * are not subject to these restrictions. 138 * 130 * 139 * The following access rights apply only to f !! 131 * A file can only receive these access rights: 140 * 132 * 141 * - %LANDLOCK_ACCESS_FS_EXECUTE: Execute a fi 133 * - %LANDLOCK_ACCESS_FS_EXECUTE: Execute a file. 142 * - %LANDLOCK_ACCESS_FS_WRITE_FILE: Open a fi !! 134 * - %LANDLOCK_ACCESS_FS_WRITE_FILE: Open a file with write access. Note that 143 * opening files for writing, you will often !! 135 * you might additionally need the %LANDLOCK_ACCESS_FS_TRUNCATE right in order 144 * %LANDLOCK_ACCESS_FS_TRUNCATE right. In m !! 136 * to overwrite files with :manpage:`open(2)` using ``O_TRUNC`` or 145 * truncate existing files when overwriting !! 137 * :manpage:`creat(2)`. 146 * - %LANDLOCK_ACCESS_FS_READ_FILE: Open a fil 138 * - %LANDLOCK_ACCESS_FS_READ_FILE: Open a file with read access. 147 * - %LANDLOCK_ACCESS_FS_TRUNCATE: Truncate a 139 * - %LANDLOCK_ACCESS_FS_TRUNCATE: Truncate a file with :manpage:`truncate(2)`, 148 * :manpage:`ftruncate(2)`, :manpage:`creat( 140 * :manpage:`ftruncate(2)`, :manpage:`creat(2)`, or :manpage:`open(2)` with 149 * ``O_TRUNC``. This access right is availa !! 141 * ``O_TRUNC``. Whether an opened file can be truncated with 150 * Landlock ABI. !! 142 * :manpage:`ftruncate(2)` is determined during :manpage:`open(2)`, in the 151 * !! 143 * same way as read and write permissions are checked during 152 * Whether an opened file can be truncated wit !! 144 * :manpage:`open(2)` using %LANDLOCK_ACCESS_FS_READ_FILE and 153 * with `ioctl(2)` is determined during :manpa !! 145 * %LANDLOCK_ACCESS_FS_WRITE_FILE. This access right is available since the 154 * read and write permissions are checked duri !! 146 * third version of the Landlock ABI. 155 * %LANDLOCK_ACCESS_FS_READ_FILE and %LANDLOCK << 156 * 147 * 157 * A directory can receive access rights relat 148 * A directory can receive access rights related to files or directories. The 158 * following access right is applied to the di 149 * following access right is applied to the directory itself, and the 159 * directories beneath it: 150 * directories beneath it: 160 * 151 * 161 * - %LANDLOCK_ACCESS_FS_READ_DIR: Open a dire 152 * - %LANDLOCK_ACCESS_FS_READ_DIR: Open a directory or list its content. 162 * 153 * 163 * However, the following access rights only a 154 * However, the following access rights only apply to the content of a 164 * directory, not the directory itself: 155 * directory, not the directory itself: 165 * 156 * 166 * - %LANDLOCK_ACCESS_FS_REMOVE_DIR: Remove an 157 * - %LANDLOCK_ACCESS_FS_REMOVE_DIR: Remove an empty directory or rename one. 167 * - %LANDLOCK_ACCESS_FS_REMOVE_FILE: Unlink ( 158 * - %LANDLOCK_ACCESS_FS_REMOVE_FILE: Unlink (or rename) a file. 168 * - %LANDLOCK_ACCESS_FS_MAKE_CHAR: Create (or 159 * - %LANDLOCK_ACCESS_FS_MAKE_CHAR: Create (or rename or link) a character 169 * device. 160 * device. 170 * - %LANDLOCK_ACCESS_FS_MAKE_DIR: Create (or 161 * - %LANDLOCK_ACCESS_FS_MAKE_DIR: Create (or rename) a directory. 171 * - %LANDLOCK_ACCESS_FS_MAKE_REG: Create (or 162 * - %LANDLOCK_ACCESS_FS_MAKE_REG: Create (or rename or link) a regular file. 172 * - %LANDLOCK_ACCESS_FS_MAKE_SOCK: Create (or 163 * - %LANDLOCK_ACCESS_FS_MAKE_SOCK: Create (or rename or link) a UNIX domain 173 * socket. 164 * socket. 174 * - %LANDLOCK_ACCESS_FS_MAKE_FIFO: Create (or 165 * - %LANDLOCK_ACCESS_FS_MAKE_FIFO: Create (or rename or link) a named pipe. 175 * - %LANDLOCK_ACCESS_FS_MAKE_BLOCK: Create (o 166 * - %LANDLOCK_ACCESS_FS_MAKE_BLOCK: Create (or rename or link) a block device. 176 * - %LANDLOCK_ACCESS_FS_MAKE_SYM: Create (or 167 * - %LANDLOCK_ACCESS_FS_MAKE_SYM: Create (or rename or link) a symbolic link. 177 * - %LANDLOCK_ACCESS_FS_REFER: Link or rename 168 * - %LANDLOCK_ACCESS_FS_REFER: Link or rename a file from or to a different 178 * directory (i.e. reparent a file hierarchy 169 * directory (i.e. reparent a file hierarchy). 179 * 170 * 180 * This access right is available since the 171 * This access right is available since the second version of the Landlock 181 * ABI. 172 * ABI. 182 * 173 * 183 * This is the only access right which is de 174 * This is the only access right which is denied by default by any ruleset, 184 * even if the right is not specified as han 175 * even if the right is not specified as handled at ruleset creation time. 185 * The only way to make a ruleset grant this 176 * The only way to make a ruleset grant this right is to explicitly allow it 186 * for a specific directory by adding a matc 177 * for a specific directory by adding a matching rule to the ruleset. 187 * 178 * 188 * In particular, when using the first Landl 179 * In particular, when using the first Landlock ABI version, Landlock will 189 * always deny attempts to reparent files be 180 * always deny attempts to reparent files between different directories. 190 * 181 * 191 * In addition to the source and destination 182 * In addition to the source and destination directories having the 192 * %LANDLOCK_ACCESS_FS_REFER access right, t 183 * %LANDLOCK_ACCESS_FS_REFER access right, the attempted link or rename 193 * operation must meet the following constra 184 * operation must meet the following constraints: 194 * 185 * 195 * * The reparented file may not gain more a 186 * * The reparented file may not gain more access rights in the destination 196 * directory than it previously had in the 187 * directory than it previously had in the source directory. If this is 197 * attempted, the operation results in an 188 * attempted, the operation results in an ``EXDEV`` error. 198 * 189 * 199 * * When linking or renaming, the ``LANDLOC 190 * * When linking or renaming, the ``LANDLOCK_ACCESS_FS_MAKE_*`` right for the 200 * respective file type must be granted fo 191 * respective file type must be granted for the destination directory. 201 * Otherwise, the operation results in an 192 * Otherwise, the operation results in an ``EACCES`` error. 202 * 193 * 203 * * When renaming, the ``LANDLOCK_ACCESS_FS 194 * * When renaming, the ``LANDLOCK_ACCESS_FS_REMOVE_*`` right for the 204 * respective file type must be granted fo 195 * respective file type must be granted for the source directory. Otherwise, 205 * the operation results in an ``EACCES`` 196 * the operation results in an ``EACCES`` error. 206 * 197 * 207 * If multiple requirements are not met, the 198 * If multiple requirements are not met, the ``EACCES`` error code takes 208 * precedence over ``EXDEV``. 199 * precedence over ``EXDEV``. 209 * 200 * 210 * The following access right applies both to << 211 * << 212 * - %LANDLOCK_ACCESS_FS_IOCTL_DEV: Invoke :ma << 213 * character or block device. << 214 * << 215 * This access right applies to all `ioctl(2 << 216 * drivers. However, the following common I << 217 * invokable independent of the %LANDLOCK_AC << 218 * << 219 * * IOCTL commands targeting file descripto << 220 * * IOCTL commands targeting file descripti << 221 * * IOCTL commands targeting file systems ( << 222 * ``FIGETBSZ``, ``FS_IOC_GETFSUUID``, ``F << 223 * * Some IOCTL commands which do not make s << 224 * whose implementations are safe and retu << 225 * (``FS_IOC_FIEMAP``, ``FICLONE``, ``FICL << 226 * << 227 * This access right is available since the << 228 * ABI. << 229 * << 230 * .. warning:: 201 * .. warning:: 231 * 202 * 232 * It is currently not possible to restrict 203 * It is currently not possible to restrict some file-related actions 233 * accessible through these syscall families 204 * accessible through these syscall families: :manpage:`chdir(2)`, 234 * :manpage:`stat(2)`, :manpage:`flock(2)`, 205 * :manpage:`stat(2)`, :manpage:`flock(2)`, :manpage:`chmod(2)`, 235 * :manpage:`chown(2)`, :manpage:`setxattr(2 206 * :manpage:`chown(2)`, :manpage:`setxattr(2)`, :manpage:`utime(2)`, 236 * :manpage:`fcntl(2)`, :manpage:`access(2)` !! 207 * :manpage:`ioctl(2)`, :manpage:`fcntl(2)`, :manpage:`access(2)`. 237 * Future Landlock evolutions will enable to 208 * Future Landlock evolutions will enable to restrict them. 238 */ 209 */ 239 /* clang-format off */ 210 /* clang-format off */ 240 #define LANDLOCK_ACCESS_FS_EXECUTE 211 #define LANDLOCK_ACCESS_FS_EXECUTE (1ULL << 0) 241 #define LANDLOCK_ACCESS_FS_WRITE_FILE 212 #define LANDLOCK_ACCESS_FS_WRITE_FILE (1ULL << 1) 242 #define LANDLOCK_ACCESS_FS_READ_FILE 213 #define LANDLOCK_ACCESS_FS_READ_FILE (1ULL << 2) 243 #define LANDLOCK_ACCESS_FS_READ_DIR 214 #define LANDLOCK_ACCESS_FS_READ_DIR (1ULL << 3) 244 #define LANDLOCK_ACCESS_FS_REMOVE_DIR 215 #define LANDLOCK_ACCESS_FS_REMOVE_DIR (1ULL << 4) 245 #define LANDLOCK_ACCESS_FS_REMOVE_FILE 216 #define LANDLOCK_ACCESS_FS_REMOVE_FILE (1ULL << 5) 246 #define LANDLOCK_ACCESS_FS_MAKE_CHAR 217 #define LANDLOCK_ACCESS_FS_MAKE_CHAR (1ULL << 6) 247 #define LANDLOCK_ACCESS_FS_MAKE_DIR 218 #define LANDLOCK_ACCESS_FS_MAKE_DIR (1ULL << 7) 248 #define LANDLOCK_ACCESS_FS_MAKE_REG 219 #define LANDLOCK_ACCESS_FS_MAKE_REG (1ULL << 8) 249 #define LANDLOCK_ACCESS_FS_MAKE_SOCK 220 #define LANDLOCK_ACCESS_FS_MAKE_SOCK (1ULL << 9) 250 #define LANDLOCK_ACCESS_FS_MAKE_FIFO 221 #define LANDLOCK_ACCESS_FS_MAKE_FIFO (1ULL << 10) 251 #define LANDLOCK_ACCESS_FS_MAKE_BLOCK 222 #define LANDLOCK_ACCESS_FS_MAKE_BLOCK (1ULL << 11) 252 #define LANDLOCK_ACCESS_FS_MAKE_SYM 223 #define LANDLOCK_ACCESS_FS_MAKE_SYM (1ULL << 12) 253 #define LANDLOCK_ACCESS_FS_REFER 224 #define LANDLOCK_ACCESS_FS_REFER (1ULL << 13) 254 #define LANDLOCK_ACCESS_FS_TRUNCATE 225 #define LANDLOCK_ACCESS_FS_TRUNCATE (1ULL << 14) 255 #define LANDLOCK_ACCESS_FS_IOCTL_DEV << 256 /* clang-format on */ 226 /* clang-format on */ 257 227 258 /** 228 /** 259 * DOC: net_access 229 * DOC: net_access 260 * 230 * 261 * Network flags 231 * Network flags 262 * ~~~~~~~~~~~~~~~~ 232 * ~~~~~~~~~~~~~~~~ 263 * 233 * 264 * These flags enable to restrict a sandboxed 234 * These flags enable to restrict a sandboxed process to a set of network 265 * actions. This is supported since the Landlo 235 * actions. This is supported since the Landlock ABI version 4. 266 * 236 * 267 * The following access rights apply to TCP po !! 237 * TCP sockets with allowed actions: 268 * 238 * 269 * - %LANDLOCK_ACCESS_NET_BIND_TCP: Bind a TCP 239 * - %LANDLOCK_ACCESS_NET_BIND_TCP: Bind a TCP socket to a local port. 270 * - %LANDLOCK_ACCESS_NET_CONNECT_TCP: Connect 240 * - %LANDLOCK_ACCESS_NET_CONNECT_TCP: Connect an active TCP socket to 271 * a remote port. 241 * a remote port. 272 */ 242 */ 273 /* clang-format off */ 243 /* clang-format off */ 274 #define LANDLOCK_ACCESS_NET_BIND_TCP 244 #define LANDLOCK_ACCESS_NET_BIND_TCP (1ULL << 0) 275 #define LANDLOCK_ACCESS_NET_CONNECT_TCP 245 #define LANDLOCK_ACCESS_NET_CONNECT_TCP (1ULL << 1) 276 /* clang-format on */ 246 /* clang-format on */ 277 #endif /* _UAPI_LINUX_LANDLOCK_H */ 247 #endif /* _UAPI_LINUX_LANDLOCK_H */ 278 248
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.