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 /** << 48 * @scoped: Bitmask of scopes (cf. `Sc << 49 * restricting a Landlock domain from << 50 * resources (e.g. IPCs). << 51 */ << 52 __u64 scoped; << 53 }; 40 }; 54 41 55 /* 42 /* 56 * sys_landlock_create_ruleset() flags: 43 * sys_landlock_create_ruleset() flags: 57 * 44 * 58 * - %LANDLOCK_CREATE_RULESET_VERSION: Get the 45 * - %LANDLOCK_CREATE_RULESET_VERSION: Get the highest supported Landlock ABI 59 * version. 46 * version. 60 */ 47 */ 61 /* clang-format off */ 48 /* clang-format off */ 62 #define LANDLOCK_CREATE_RULESET_VERSION 49 #define LANDLOCK_CREATE_RULESET_VERSION (1U << 0) 63 /* clang-format on */ 50 /* clang-format on */ 64 51 65 /** 52 /** 66 * enum landlock_rule_type - Landlock rule typ 53 * enum landlock_rule_type - Landlock rule type 67 * 54 * 68 * Argument of sys_landlock_add_rule(). 55 * Argument of sys_landlock_add_rule(). 69 */ 56 */ 70 enum landlock_rule_type { 57 enum landlock_rule_type { 71 /** 58 /** 72 * @LANDLOCK_RULE_PATH_BENEATH: Type o 59 * @LANDLOCK_RULE_PATH_BENEATH: Type of a &struct 73 * landlock_path_beneath_attr . 60 * landlock_path_beneath_attr . 74 */ 61 */ 75 LANDLOCK_RULE_PATH_BENEATH = 1, 62 LANDLOCK_RULE_PATH_BENEATH = 1, 76 /** 63 /** 77 * @LANDLOCK_RULE_NET_PORT: Type of a 64 * @LANDLOCK_RULE_NET_PORT: Type of a &struct 78 * landlock_net_port_attr . 65 * landlock_net_port_attr . 79 */ 66 */ 80 LANDLOCK_RULE_NET_PORT, 67 LANDLOCK_RULE_NET_PORT, 81 }; 68 }; 82 69 83 /** 70 /** 84 * struct landlock_path_beneath_attr - Path hi 71 * struct landlock_path_beneath_attr - Path hierarchy definition 85 * 72 * 86 * Argument of sys_landlock_add_rule(). 73 * Argument of sys_landlock_add_rule(). 87 */ 74 */ 88 struct landlock_path_beneath_attr { 75 struct landlock_path_beneath_attr { 89 /** 76 /** 90 * @allowed_access: Bitmask of allowed 77 * @allowed_access: Bitmask of allowed actions for this file hierarchy 91 * (cf. `Filesystem flags`_). 78 * (cf. `Filesystem flags`_). 92 */ 79 */ 93 __u64 allowed_access; 80 __u64 allowed_access; 94 /** 81 /** 95 * @parent_fd: File descriptor, prefer 82 * @parent_fd: File descriptor, preferably opened with ``O_PATH``, 96 * which identifies the parent directo 83 * which identifies the parent directory of a file hierarchy, or just a 97 * file. 84 * file. 98 */ 85 */ 99 __s32 parent_fd; 86 __s32 parent_fd; 100 /* 87 /* 101 * This struct is packed to avoid trai 88 * This struct is packed to avoid trailing reserved members. 102 * Cf. security/landlock/syscalls.c:bu 89 * Cf. security/landlock/syscalls.c:build_check_abi() 103 */ 90 */ 104 } __attribute__((packed)); 91 } __attribute__((packed)); 105 92 106 /** 93 /** 107 * struct landlock_net_port_attr - Network por 94 * struct landlock_net_port_attr - Network port definition 108 * 95 * 109 * Argument of sys_landlock_add_rule(). 96 * Argument of sys_landlock_add_rule(). 110 */ 97 */ 111 struct landlock_net_port_attr { 98 struct landlock_net_port_attr { 112 /** 99 /** 113 * @allowed_access: Bitmask of allowed !! 100 * @allowed_access: Bitmask of allowed access network for a port 114 * (cf. `Network flags`_). 101 * (cf. `Network flags`_). 115 */ 102 */ 116 __u64 allowed_access; 103 __u64 allowed_access; 117 /** 104 /** 118 * @port: Network port in host endiann 105 * @port: Network port in host endianness. 119 * 106 * 120 * It should be noted that port 0 pass !! 107 * It should be noted that port 0 passed to :manpage:`bind(2)` will 121 * to an available port from the ephem !! 108 * bind to an available port from a specific port range. This can be 122 * configured with the ``/proc/sys/net !! 109 * configured thanks to the ``/proc/sys/net/ipv4/ip_local_port_range`` 123 * (also used for IPv6). !! 110 * sysctl (also used for IPv6). A Landlock rule with port 0 and the 124 * !! 111 * ``LANDLOCK_ACCESS_NET_BIND_TCP`` right means that requesting to bind 125 * A Landlock rule with port 0 and the !! 112 * on port 0 is allowed and it will automatically translate to binding 126 * right means that requesting to bind !! 113 * on the related port range. 127 * automatically translate to binding << 128 */ 114 */ 129 __u64 port; 115 __u64 port; 130 }; 116 }; 131 117 132 /** 118 /** 133 * DOC: fs_access 119 * DOC: fs_access 134 * 120 * 135 * 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. 136 * &struct landlock_path_beneath_attr) includi 122 * &struct landlock_path_beneath_attr) including a bitmask of access. 137 * 123 * 138 * Filesystem flags 124 * Filesystem flags 139 * ~~~~~~~~~~~~~~~~ 125 * ~~~~~~~~~~~~~~~~ 140 * 126 * 141 * These flags enable to restrict a sandboxed 127 * These flags enable to restrict a sandboxed process to a set of actions on 142 * files and directories. Files or directorie 128 * files and directories. Files or directories opened before the sandboxing 143 * are not subject to these restrictions. 129 * are not subject to these restrictions. 144 * 130 * 145 * The following access rights apply only to f 131 * The following access rights apply only to files: 146 * 132 * 147 * - %LANDLOCK_ACCESS_FS_EXECUTE: Execute a fi 133 * - %LANDLOCK_ACCESS_FS_EXECUTE: Execute a file. 148 * - %LANDLOCK_ACCESS_FS_WRITE_FILE: Open a fi !! 134 * - %LANDLOCK_ACCESS_FS_WRITE_FILE: Open a file with write access. Note that 149 * opening files for writing, you will often !! 135 * you might additionally need the %LANDLOCK_ACCESS_FS_TRUNCATE right in order 150 * %LANDLOCK_ACCESS_FS_TRUNCATE right. In m !! 136 * to overwrite files with :manpage:`open(2)` using ``O_TRUNC`` or 151 * truncate existing files when overwriting !! 137 * :manpage:`creat(2)`. 152 * - %LANDLOCK_ACCESS_FS_READ_FILE: Open a fil 138 * - %LANDLOCK_ACCESS_FS_READ_FILE: Open a file with read access. 153 * - %LANDLOCK_ACCESS_FS_TRUNCATE: Truncate a 139 * - %LANDLOCK_ACCESS_FS_TRUNCATE: Truncate a file with :manpage:`truncate(2)`, 154 * :manpage:`ftruncate(2)`, :manpage:`creat( 140 * :manpage:`ftruncate(2)`, :manpage:`creat(2)`, or :manpage:`open(2)` with 155 * ``O_TRUNC``. This access right is availa 141 * ``O_TRUNC``. This access right is available since the third version of the 156 * Landlock ABI. 142 * Landlock ABI. 157 * 143 * 158 * Whether an opened file can be truncated wit 144 * Whether an opened file can be truncated with :manpage:`ftruncate(2)` or used 159 * with `ioctl(2)` is determined during :manpa 145 * with `ioctl(2)` is determined during :manpage:`open(2)`, in the same way as 160 * read and write permissions are checked duri 146 * read and write permissions are checked during :manpage:`open(2)` using 161 * %LANDLOCK_ACCESS_FS_READ_FILE and %LANDLOCK 147 * %LANDLOCK_ACCESS_FS_READ_FILE and %LANDLOCK_ACCESS_FS_WRITE_FILE. 162 * 148 * 163 * A directory can receive access rights relat 149 * A directory can receive access rights related to files or directories. The 164 * following access right is applied to the di 150 * following access right is applied to the directory itself, and the 165 * directories beneath it: 151 * directories beneath it: 166 * 152 * 167 * - %LANDLOCK_ACCESS_FS_READ_DIR: Open a dire 153 * - %LANDLOCK_ACCESS_FS_READ_DIR: Open a directory or list its content. 168 * 154 * 169 * However, the following access rights only a 155 * However, the following access rights only apply to the content of a 170 * directory, not the directory itself: 156 * directory, not the directory itself: 171 * 157 * 172 * - %LANDLOCK_ACCESS_FS_REMOVE_DIR: Remove an 158 * - %LANDLOCK_ACCESS_FS_REMOVE_DIR: Remove an empty directory or rename one. 173 * - %LANDLOCK_ACCESS_FS_REMOVE_FILE: Unlink ( 159 * - %LANDLOCK_ACCESS_FS_REMOVE_FILE: Unlink (or rename) a file. 174 * - %LANDLOCK_ACCESS_FS_MAKE_CHAR: Create (or 160 * - %LANDLOCK_ACCESS_FS_MAKE_CHAR: Create (or rename or link) a character 175 * device. 161 * device. 176 * - %LANDLOCK_ACCESS_FS_MAKE_DIR: Create (or 162 * - %LANDLOCK_ACCESS_FS_MAKE_DIR: Create (or rename) a directory. 177 * - %LANDLOCK_ACCESS_FS_MAKE_REG: Create (or 163 * - %LANDLOCK_ACCESS_FS_MAKE_REG: Create (or rename or link) a regular file. 178 * - %LANDLOCK_ACCESS_FS_MAKE_SOCK: Create (or 164 * - %LANDLOCK_ACCESS_FS_MAKE_SOCK: Create (or rename or link) a UNIX domain 179 * socket. 165 * socket. 180 * - %LANDLOCK_ACCESS_FS_MAKE_FIFO: Create (or 166 * - %LANDLOCK_ACCESS_FS_MAKE_FIFO: Create (or rename or link) a named pipe. 181 * - %LANDLOCK_ACCESS_FS_MAKE_BLOCK: Create (o 167 * - %LANDLOCK_ACCESS_FS_MAKE_BLOCK: Create (or rename or link) a block device. 182 * - %LANDLOCK_ACCESS_FS_MAKE_SYM: Create (or 168 * - %LANDLOCK_ACCESS_FS_MAKE_SYM: Create (or rename or link) a symbolic link. 183 * - %LANDLOCK_ACCESS_FS_REFER: Link or rename 169 * - %LANDLOCK_ACCESS_FS_REFER: Link or rename a file from or to a different 184 * directory (i.e. reparent a file hierarchy 170 * directory (i.e. reparent a file hierarchy). 185 * 171 * 186 * This access right is available since the 172 * This access right is available since the second version of the Landlock 187 * ABI. 173 * ABI. 188 * 174 * 189 * This is the only access right which is de 175 * This is the only access right which is denied by default by any ruleset, 190 * even if the right is not specified as han 176 * even if the right is not specified as handled at ruleset creation time. 191 * The only way to make a ruleset grant this 177 * The only way to make a ruleset grant this right is to explicitly allow it 192 * for a specific directory by adding a matc 178 * for a specific directory by adding a matching rule to the ruleset. 193 * 179 * 194 * In particular, when using the first Landl 180 * In particular, when using the first Landlock ABI version, Landlock will 195 * always deny attempts to reparent files be 181 * always deny attempts to reparent files between different directories. 196 * 182 * 197 * In addition to the source and destination 183 * In addition to the source and destination directories having the 198 * %LANDLOCK_ACCESS_FS_REFER access right, t 184 * %LANDLOCK_ACCESS_FS_REFER access right, the attempted link or rename 199 * operation must meet the following constra 185 * operation must meet the following constraints: 200 * 186 * 201 * * The reparented file may not gain more a 187 * * The reparented file may not gain more access rights in the destination 202 * directory than it previously had in the 188 * directory than it previously had in the source directory. If this is 203 * attempted, the operation results in an 189 * attempted, the operation results in an ``EXDEV`` error. 204 * 190 * 205 * * When linking or renaming, the ``LANDLOC 191 * * When linking or renaming, the ``LANDLOCK_ACCESS_FS_MAKE_*`` right for the 206 * respective file type must be granted fo 192 * respective file type must be granted for the destination directory. 207 * Otherwise, the operation results in an 193 * Otherwise, the operation results in an ``EACCES`` error. 208 * 194 * 209 * * When renaming, the ``LANDLOCK_ACCESS_FS 195 * * When renaming, the ``LANDLOCK_ACCESS_FS_REMOVE_*`` right for the 210 * respective file type must be granted fo 196 * respective file type must be granted for the source directory. Otherwise, 211 * the operation results in an ``EACCES`` 197 * the operation results in an ``EACCES`` error. 212 * 198 * 213 * If multiple requirements are not met, the 199 * If multiple requirements are not met, the ``EACCES`` error code takes 214 * precedence over ``EXDEV``. 200 * precedence over ``EXDEV``. 215 * 201 * 216 * The following access right applies both to 202 * The following access right applies both to files and directories: 217 * 203 * 218 * - %LANDLOCK_ACCESS_FS_IOCTL_DEV: Invoke :ma 204 * - %LANDLOCK_ACCESS_FS_IOCTL_DEV: Invoke :manpage:`ioctl(2)` commands on an opened 219 * character or block device. 205 * character or block device. 220 * 206 * 221 * This access right applies to all `ioctl(2 207 * This access right applies to all `ioctl(2)` commands implemented by device 222 * drivers. However, the following common I 208 * drivers. However, the following common IOCTL commands continue to be 223 * invokable independent of the %LANDLOCK_AC 209 * invokable independent of the %LANDLOCK_ACCESS_FS_IOCTL_DEV right: 224 * 210 * 225 * * IOCTL commands targeting file descripto 211 * * IOCTL commands targeting file descriptors (``FIOCLEX``, ``FIONCLEX``), 226 * * IOCTL commands targeting file descripti 212 * * IOCTL commands targeting file descriptions (``FIONBIO``, ``FIOASYNC``), 227 * * IOCTL commands targeting file systems ( 213 * * IOCTL commands targeting file systems (``FIFREEZE``, ``FITHAW``, 228 * ``FIGETBSZ``, ``FS_IOC_GETFSUUID``, ``F 214 * ``FIGETBSZ``, ``FS_IOC_GETFSUUID``, ``FS_IOC_GETFSSYSFSPATH``) 229 * * Some IOCTL commands which do not make s 215 * * Some IOCTL commands which do not make sense when used with devices, but 230 * whose implementations are safe and retu 216 * whose implementations are safe and return the right error codes 231 * (``FS_IOC_FIEMAP``, ``FICLONE``, ``FICL 217 * (``FS_IOC_FIEMAP``, ``FICLONE``, ``FICLONERANGE``, ``FIDEDUPERANGE``) 232 * 218 * 233 * This access right is available since the 219 * This access right is available since the fifth version of the Landlock 234 * ABI. 220 * ABI. 235 * 221 * 236 * .. warning:: 222 * .. warning:: 237 * 223 * 238 * It is currently not possible to restrict 224 * It is currently not possible to restrict some file-related actions 239 * accessible through these syscall families 225 * accessible through these syscall families: :manpage:`chdir(2)`, 240 * :manpage:`stat(2)`, :manpage:`flock(2)`, 226 * :manpage:`stat(2)`, :manpage:`flock(2)`, :manpage:`chmod(2)`, 241 * :manpage:`chown(2)`, :manpage:`setxattr(2 227 * :manpage:`chown(2)`, :manpage:`setxattr(2)`, :manpage:`utime(2)`, 242 * :manpage:`fcntl(2)`, :manpage:`access(2)` 228 * :manpage:`fcntl(2)`, :manpage:`access(2)`. 243 * Future Landlock evolutions will enable to 229 * Future Landlock evolutions will enable to restrict them. 244 */ 230 */ 245 /* clang-format off */ 231 /* clang-format off */ 246 #define LANDLOCK_ACCESS_FS_EXECUTE 232 #define LANDLOCK_ACCESS_FS_EXECUTE (1ULL << 0) 247 #define LANDLOCK_ACCESS_FS_WRITE_FILE 233 #define LANDLOCK_ACCESS_FS_WRITE_FILE (1ULL << 1) 248 #define LANDLOCK_ACCESS_FS_READ_FILE 234 #define LANDLOCK_ACCESS_FS_READ_FILE (1ULL << 2) 249 #define LANDLOCK_ACCESS_FS_READ_DIR 235 #define LANDLOCK_ACCESS_FS_READ_DIR (1ULL << 3) 250 #define LANDLOCK_ACCESS_FS_REMOVE_DIR 236 #define LANDLOCK_ACCESS_FS_REMOVE_DIR (1ULL << 4) 251 #define LANDLOCK_ACCESS_FS_REMOVE_FILE 237 #define LANDLOCK_ACCESS_FS_REMOVE_FILE (1ULL << 5) 252 #define LANDLOCK_ACCESS_FS_MAKE_CHAR 238 #define LANDLOCK_ACCESS_FS_MAKE_CHAR (1ULL << 6) 253 #define LANDLOCK_ACCESS_FS_MAKE_DIR 239 #define LANDLOCK_ACCESS_FS_MAKE_DIR (1ULL << 7) 254 #define LANDLOCK_ACCESS_FS_MAKE_REG 240 #define LANDLOCK_ACCESS_FS_MAKE_REG (1ULL << 8) 255 #define LANDLOCK_ACCESS_FS_MAKE_SOCK 241 #define LANDLOCK_ACCESS_FS_MAKE_SOCK (1ULL << 9) 256 #define LANDLOCK_ACCESS_FS_MAKE_FIFO 242 #define LANDLOCK_ACCESS_FS_MAKE_FIFO (1ULL << 10) 257 #define LANDLOCK_ACCESS_FS_MAKE_BLOCK 243 #define LANDLOCK_ACCESS_FS_MAKE_BLOCK (1ULL << 11) 258 #define LANDLOCK_ACCESS_FS_MAKE_SYM 244 #define LANDLOCK_ACCESS_FS_MAKE_SYM (1ULL << 12) 259 #define LANDLOCK_ACCESS_FS_REFER 245 #define LANDLOCK_ACCESS_FS_REFER (1ULL << 13) 260 #define LANDLOCK_ACCESS_FS_TRUNCATE 246 #define LANDLOCK_ACCESS_FS_TRUNCATE (1ULL << 14) 261 #define LANDLOCK_ACCESS_FS_IOCTL_DEV 247 #define LANDLOCK_ACCESS_FS_IOCTL_DEV (1ULL << 15) 262 /* clang-format on */ 248 /* clang-format on */ 263 249 264 /** 250 /** 265 * DOC: net_access 251 * DOC: net_access 266 * 252 * 267 * Network flags 253 * Network flags 268 * ~~~~~~~~~~~~~~~~ 254 * ~~~~~~~~~~~~~~~~ 269 * 255 * 270 * These flags enable to restrict a sandboxed 256 * These flags enable to restrict a sandboxed process to a set of network 271 * actions. This is supported since the Landlo 257 * actions. This is supported since the Landlock ABI version 4. 272 * 258 * 273 * The following access rights apply to TCP po !! 259 * TCP sockets with allowed actions: 274 * 260 * 275 * - %LANDLOCK_ACCESS_NET_BIND_TCP: Bind a TCP 261 * - %LANDLOCK_ACCESS_NET_BIND_TCP: Bind a TCP socket to a local port. 276 * - %LANDLOCK_ACCESS_NET_CONNECT_TCP: Connect 262 * - %LANDLOCK_ACCESS_NET_CONNECT_TCP: Connect an active TCP socket to 277 * a remote port. 263 * a remote port. 278 */ 264 */ 279 /* clang-format off */ 265 /* clang-format off */ 280 #define LANDLOCK_ACCESS_NET_BIND_TCP 266 #define LANDLOCK_ACCESS_NET_BIND_TCP (1ULL << 0) 281 #define LANDLOCK_ACCESS_NET_CONNECT_TCP 267 #define LANDLOCK_ACCESS_NET_CONNECT_TCP (1ULL << 1) 282 /* clang-format on */ 268 /* clang-format on */ 283 << 284 /** << 285 * DOC: scope << 286 * << 287 * Scope flags << 288 * ~~~~~~~~~~~ << 289 * << 290 * These flags enable to isolate a sandboxed p << 291 * Setting a flag for a ruleset will isolate t << 292 * connections to resources outside the domain << 293 * << 294 * Scopes: << 295 * << 296 * - %LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET: Res << 297 * connecting to an abstract UNIX socket cre << 298 * related Landlock domain (e.g. a parent do << 299 * - %LANDLOCK_SCOPE_SIGNAL: Restrict a sandbo << 300 * to another process outside the domain. << 301 */ << 302 /* clang-format off */ << 303 #define LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET << 304 #define LANDLOCK_SCOPE_SIGNAL << 305 /* clang-format on*/ << 306 << 307 #endif /* _UAPI_LINUX_LANDLOCK_H */ 269 #endif /* _UAPI_LINUX_LANDLOCK_H */ 308 270
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.