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. This is needed for backward 25 * compatibility reasons. 26 */ 27 __u64 handled_access_fs; 28 }; 29 30 /* 31 * sys_landlock_create_ruleset() flags: 32 * 33 * - %LANDLOCK_CREATE_RULESET_VERSION: Get the highest supported Landlock ABI 34 * version. 35 */ 36 /* clang-format off */ 37 #define LANDLOCK_CREATE_RULESET_VERSION (1U << 0) 38 /* clang-format on */ 39 40 /** 41 * enum landlock_rule_type - Landlock rule type 42 * 43 * Argument of sys_landlock_add_rule(). 44 */ 45 enum landlock_rule_type { 46 /** 47 * @LANDLOCK_RULE_PATH_BENEATH: Type of a &struct 48 * landlock_path_beneath_attr . 49 */ 50 LANDLOCK_RULE_PATH_BENEATH = 1, 51 }; 52 53 /** 54 * struct landlock_path_beneath_attr - Path hierarchy definition 55 * 56 * Argument of sys_landlock_add_rule(). 57 */ 58 struct landlock_path_beneath_attr { 59 /** 60 * @allowed_access: Bitmask of allowed actions for this file hierarchy 61 * (cf. `Filesystem flags`_). 62 */ 63 __u64 allowed_access; 64 /** 65 * @parent_fd: File descriptor, preferably opened with ``O_PATH``, 66 * which identifies the parent directory of a file hierarchy, or just a 67 * file. 68 */ 69 __s32 parent_fd; 70 /* 71 * This struct is packed to avoid trailing reserved members. 72 * Cf. security/landlock/syscalls.c:build_check_abi() 73 */ 74 } __attribute__((packed)); 75 76 /** 77 * DOC: fs_access 78 * 79 * A set of actions on kernel objects may be defined by an attribute (e.g. 80 * &struct landlock_path_beneath_attr) including a bitmask of access. 81 * 82 * Filesystem flags 83 * ~~~~~~~~~~~~~~~~ 84 * 85 * These flags enable to restrict a sandboxed process to a set of actions on 86 * files and directories. Files or directories opened before the sandboxing 87 * are not subject to these restrictions. 88 * 89 * A file can only receive these access rights: 90 * 91 * - %LANDLOCK_ACCESS_FS_EXECUTE: Execute a file. 92 * - %LANDLOCK_ACCESS_FS_WRITE_FILE: Open a file with write access. 93 * - %LANDLOCK_ACCESS_FS_READ_FILE: Open a file with read access. 94 * 95 * A directory can receive access rights related to files or directories. The 96 * following access right is applied to the directory itself, and the 97 * directories beneath it: 98 * 99 * - %LANDLOCK_ACCESS_FS_READ_DIR: Open a directory or list its content. 100 * 101 * However, the following access rights only apply to the content of a 102 * directory, not the directory itself: 103 * 104 * - %LANDLOCK_ACCESS_FS_REMOVE_DIR: Remove an empty directory or rename one. 105 * - %LANDLOCK_ACCESS_FS_REMOVE_FILE: Unlink (or rename) a file. 106 * - %LANDLOCK_ACCESS_FS_MAKE_CHAR: Create (or rename or link) a character 107 * device. 108 * - %LANDLOCK_ACCESS_FS_MAKE_DIR: Create (or rename) a directory. 109 * - %LANDLOCK_ACCESS_FS_MAKE_REG: Create (or rename or link) a regular file. 110 * - %LANDLOCK_ACCESS_FS_MAKE_SOCK: Create (or rename or link) a UNIX domain 111 * socket. 112 * - %LANDLOCK_ACCESS_FS_MAKE_FIFO: Create (or rename or link) a named pipe. 113 * - %LANDLOCK_ACCESS_FS_MAKE_BLOCK: Create (or rename or link) a block device. 114 * - %LANDLOCK_ACCESS_FS_MAKE_SYM: Create (or rename or link) a symbolic link. 115 * 116 * .. warning:: 117 * 118 * It is currently not possible to restrict some file-related actions 119 * accessible through these syscall families: :manpage:`chdir(2)`, 120 * :manpage:`truncate(2)`, :manpage:`stat(2)`, :manpage:`flock(2)`, 121 * :manpage:`chmod(2)`, :manpage:`chown(2)`, :manpage:`setxattr(2)`, 122 * :manpage:`utime(2)`, :manpage:`ioctl(2)`, :manpage:`fcntl(2)`, 123 * :manpage:`access(2)`. 124 * Future Landlock evolutions will enable to restrict them. 125 */ 126 /* clang-format off */ 127 #define LANDLOCK_ACCESS_FS_EXECUTE (1ULL << 0) 128 #define LANDLOCK_ACCESS_FS_WRITE_FILE (1ULL << 1) 129 #define LANDLOCK_ACCESS_FS_READ_FILE (1ULL << 2) 130 #define LANDLOCK_ACCESS_FS_READ_DIR (1ULL << 3) 131 #define LANDLOCK_ACCESS_FS_REMOVE_DIR (1ULL << 4) 132 #define LANDLOCK_ACCESS_FS_REMOVE_FILE (1ULL << 5) 133 #define LANDLOCK_ACCESS_FS_MAKE_CHAR (1ULL << 6) 134 #define LANDLOCK_ACCESS_FS_MAKE_DIR (1ULL << 7) 135 #define LANDLOCK_ACCESS_FS_MAKE_REG (1ULL << 8) 136 #define LANDLOCK_ACCESS_FS_MAKE_SOCK (1ULL << 9) 137 #define LANDLOCK_ACCESS_FS_MAKE_FIFO (1ULL << 10) 138 #define LANDLOCK_ACCESS_FS_MAKE_BLOCK (1ULL << 11) 139 #define LANDLOCK_ACCESS_FS_MAKE_SYM (1ULL << 12) 140 /* clang-format on */ 141 142 #endif /* _UAPI_LINUX_LANDLOCK_H */ 143