1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux 1 2 /* 3 * Landlock - User space API 4 * 5 * Copyright © 2017-2020 Mickaël Salaün <mi 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 defi 16 * 17 * Argument of sys_landlock_create_ruleset(). 18 * 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 */ 36 struct landlock_ruleset_attr { 37 /** 38 * @handled_access_fs: Bitmask of hand 39 * (cf. `Filesystem flags`_). 40 */ 41 __u64 handled_access_fs; 42 /** 43 * @handled_access_net: Bitmask of han 44 * flags`_). 45 */ 46 __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 }; 54 55 /* 56 * sys_landlock_create_ruleset() flags: 57 * 58 * - %LANDLOCK_CREATE_RULESET_VERSION: Get the 59 * version. 60 */ 61 /* clang-format off */ 62 #define LANDLOCK_CREATE_RULESET_VERSION 63 /* clang-format on */ 64 65 /** 66 * enum landlock_rule_type - Landlock rule typ 67 * 68 * Argument of sys_landlock_add_rule(). 69 */ 70 enum landlock_rule_type { 71 /** 72 * @LANDLOCK_RULE_PATH_BENEATH: Type o 73 * landlock_path_beneath_attr . 74 */ 75 LANDLOCK_RULE_PATH_BENEATH = 1, 76 /** 77 * @LANDLOCK_RULE_NET_PORT: Type of a 78 * landlock_net_port_attr . 79 */ 80 LANDLOCK_RULE_NET_PORT, 81 }; 82 83 /** 84 * struct landlock_path_beneath_attr - Path hi 85 * 86 * Argument of sys_landlock_add_rule(). 87 */ 88 struct landlock_path_beneath_attr { 89 /** 90 * @allowed_access: Bitmask of allowed 91 * (cf. `Filesystem flags`_). 92 */ 93 __u64 allowed_access; 94 /** 95 * @parent_fd: File descriptor, prefer 96 * which identifies the parent directo 97 * file. 98 */ 99 __s32 parent_fd; 100 /* 101 * This struct is packed to avoid trai 102 * Cf. security/landlock/syscalls.c:bu 103 */ 104 } __attribute__((packed)); 105 106 /** 107 * struct landlock_net_port_attr - Network por 108 * 109 * Argument of sys_landlock_add_rule(). 110 */ 111 struct landlock_net_port_attr { 112 /** 113 * @allowed_access: Bitmask of allowed 114 * (cf. `Network flags`_). 115 */ 116 __u64 allowed_access; 117 /** 118 * @port: Network port in host endiann 119 * 120 * It should be noted that port 0 pass 121 * to an available port from the ephem 122 * configured with the ``/proc/sys/net 123 * (also used for IPv6). 124 * 125 * A Landlock rule with port 0 and the 126 * right means that requesting to bind 127 * automatically translate to binding 128 */ 129 __u64 port; 130 }; 131 132 /** 133 * DOC: fs_access 134 * 135 * A set of actions on kernel objects may be d 136 * &struct landlock_path_beneath_attr) includi 137 * 138 * Filesystem flags 139 * ~~~~~~~~~~~~~~~~ 140 * 141 * These flags enable to restrict a sandboxed 142 * files and directories. Files or directorie 143 * are not subject to these restrictions. 144 * 145 * The following access rights apply only to f 146 * 147 * - %LANDLOCK_ACCESS_FS_EXECUTE: Execute a fi 148 * - %LANDLOCK_ACCESS_FS_WRITE_FILE: Open a fi 149 * opening files for writing, you will often 150 * %LANDLOCK_ACCESS_FS_TRUNCATE right. In m 151 * truncate existing files when overwriting 152 * - %LANDLOCK_ACCESS_FS_READ_FILE: Open a fil 153 * - %LANDLOCK_ACCESS_FS_TRUNCATE: Truncate a 154 * :manpage:`ftruncate(2)`, :manpage:`creat( 155 * ``O_TRUNC``. This access right is availa 156 * Landlock ABI. 157 * 158 * Whether an opened file can be truncated wit 159 * with `ioctl(2)` is determined during :manpa 160 * read and write permissions are checked duri 161 * %LANDLOCK_ACCESS_FS_READ_FILE and %LANDLOCK 162 * 163 * A directory can receive access rights relat 164 * following access right is applied to the di 165 * directories beneath it: 166 * 167 * - %LANDLOCK_ACCESS_FS_READ_DIR: Open a dire 168 * 169 * However, the following access rights only a 170 * directory, not the directory itself: 171 * 172 * - %LANDLOCK_ACCESS_FS_REMOVE_DIR: Remove an 173 * - %LANDLOCK_ACCESS_FS_REMOVE_FILE: Unlink ( 174 * - %LANDLOCK_ACCESS_FS_MAKE_CHAR: Create (or 175 * device. 176 * - %LANDLOCK_ACCESS_FS_MAKE_DIR: Create (or 177 * - %LANDLOCK_ACCESS_FS_MAKE_REG: Create (or 178 * - %LANDLOCK_ACCESS_FS_MAKE_SOCK: Create (or 179 * socket. 180 * - %LANDLOCK_ACCESS_FS_MAKE_FIFO: Create (or 181 * - %LANDLOCK_ACCESS_FS_MAKE_BLOCK: Create (o 182 * - %LANDLOCK_ACCESS_FS_MAKE_SYM: Create (or 183 * - %LANDLOCK_ACCESS_FS_REFER: Link or rename 184 * directory (i.e. reparent a file hierarchy 185 * 186 * This access right is available since the 187 * ABI. 188 * 189 * This is the only access right which is de 190 * even if the right is not specified as han 191 * The only way to make a ruleset grant this 192 * for a specific directory by adding a matc 193 * 194 * In particular, when using the first Landl 195 * always deny attempts to reparent files be 196 * 197 * In addition to the source and destination 198 * %LANDLOCK_ACCESS_FS_REFER access right, t 199 * operation must meet the following constra 200 * 201 * * The reparented file may not gain more a 202 * directory than it previously had in the 203 * attempted, the operation results in an 204 * 205 * * When linking or renaming, the ``LANDLOC 206 * respective file type must be granted fo 207 * Otherwise, the operation results in an 208 * 209 * * When renaming, the ``LANDLOCK_ACCESS_FS 210 * respective file type must be granted fo 211 * the operation results in an ``EACCES`` 212 * 213 * If multiple requirements are not met, the 214 * precedence over ``EXDEV``. 215 * 216 * The following access right applies both to 217 * 218 * - %LANDLOCK_ACCESS_FS_IOCTL_DEV: Invoke :ma 219 * character or block device. 220 * 221 * This access right applies to all `ioctl(2 222 * drivers. However, the following common I 223 * invokable independent of the %LANDLOCK_AC 224 * 225 * * IOCTL commands targeting file descripto 226 * * IOCTL commands targeting file descripti 227 * * IOCTL commands targeting file systems ( 228 * ``FIGETBSZ``, ``FS_IOC_GETFSUUID``, ``F 229 * * Some IOCTL commands which do not make s 230 * whose implementations are safe and retu 231 * (``FS_IOC_FIEMAP``, ``FICLONE``, ``FICL 232 * 233 * This access right is available since the 234 * ABI. 235 * 236 * .. warning:: 237 * 238 * It is currently not possible to restrict 239 * accessible through these syscall families 240 * :manpage:`stat(2)`, :manpage:`flock(2)`, 241 * :manpage:`chown(2)`, :manpage:`setxattr(2 242 * :manpage:`fcntl(2)`, :manpage:`access(2)` 243 * Future Landlock evolutions will enable to 244 */ 245 /* clang-format off */ 246 #define LANDLOCK_ACCESS_FS_EXECUTE 247 #define LANDLOCK_ACCESS_FS_WRITE_FILE 248 #define LANDLOCK_ACCESS_FS_READ_FILE 249 #define LANDLOCK_ACCESS_FS_READ_DIR 250 #define LANDLOCK_ACCESS_FS_REMOVE_DIR 251 #define LANDLOCK_ACCESS_FS_REMOVE_FILE 252 #define LANDLOCK_ACCESS_FS_MAKE_CHAR 253 #define LANDLOCK_ACCESS_FS_MAKE_DIR 254 #define LANDLOCK_ACCESS_FS_MAKE_REG 255 #define LANDLOCK_ACCESS_FS_MAKE_SOCK 256 #define LANDLOCK_ACCESS_FS_MAKE_FIFO 257 #define LANDLOCK_ACCESS_FS_MAKE_BLOCK 258 #define LANDLOCK_ACCESS_FS_MAKE_SYM 259 #define LANDLOCK_ACCESS_FS_REFER 260 #define LANDLOCK_ACCESS_FS_TRUNCATE 261 #define LANDLOCK_ACCESS_FS_IOCTL_DEV 262 /* clang-format on */ 263 264 /** 265 * DOC: net_access 266 * 267 * Network flags 268 * ~~~~~~~~~~~~~~~~ 269 * 270 * These flags enable to restrict a sandboxed 271 * actions. This is supported since the Landlo 272 * 273 * The following access rights apply to TCP po 274 * 275 * - %LANDLOCK_ACCESS_NET_BIND_TCP: Bind a TCP 276 * - %LANDLOCK_ACCESS_NET_CONNECT_TCP: Connect 277 * a remote port. 278 */ 279 /* clang-format off */ 280 #define LANDLOCK_ACCESS_NET_BIND_TCP 281 #define LANDLOCK_ACCESS_NET_CONNECT_TCP 282 /* 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 */ 308
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.