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