1*4b9c6d91SCole Faust /* Copyright 2022 The ChromiumOS Authors 2*4b9c6d91SCole Faust * Use of this source code is governed by a BSD-style license that can be 3*4b9c6d91SCole Faust * found in the LICENSE file. 4*4b9c6d91SCole Faust */ 5*4b9c6d91SCole Faust 6*4b9c6d91SCole Faust /* 7*4b9c6d91SCole Faust * Landlock system definitions. 8*4b9c6d91SCole Faust * 9*4b9c6d91SCole Faust * These definitions are based on <linux/landlock.h>. However, because we 10*4b9c6d91SCole Faust * can't guarantee that header will be available on all systems that need to 11*4b9c6d91SCole Faust * build Minijail, they are extracted here. 12*4b9c6d91SCole Faust */ 13*4b9c6d91SCole Faust 14*4b9c6d91SCole Faust #ifndef _LANDLOCK_H 15*4b9c6d91SCole Faust #define _LANDLOCK_H 16*4b9c6d91SCole Faust 17*4b9c6d91SCole Faust #include <linux/types.h> 18*4b9c6d91SCole Faust 19*4b9c6d91SCole Faust /** 20*4b9c6d91SCole Faust * struct landlock_ruleset_attr - Ruleset definition 21*4b9c6d91SCole Faust * 22*4b9c6d91SCole Faust * Argument of sys_landlock_create_ruleset(). This structure can grow in 23*4b9c6d91SCole Faust * future versions. 24*4b9c6d91SCole Faust */ 25*4b9c6d91SCole Faust struct minijail_landlock_ruleset_attr { 26*4b9c6d91SCole Faust /** 27*4b9c6d91SCole Faust * @handled_access_fs: Bitmask of actions (cf. `Filesystem flags`_) 28*4b9c6d91SCole Faust * that is handled by this ruleset and should then be forbidden if no 29*4b9c6d91SCole Faust * rule explicitly allow them. This is needed for backward 30*4b9c6d91SCole Faust * compatibility reasons. 31*4b9c6d91SCole Faust */ 32*4b9c6d91SCole Faust __u64 handled_access_fs; 33*4b9c6d91SCole Faust }; 34*4b9c6d91SCole Faust 35*4b9c6d91SCole Faust /* 36*4b9c6d91SCole Faust * sys_landlock_create_ruleset() flags: 37*4b9c6d91SCole Faust * 38*4b9c6d91SCole Faust * - %LANDLOCK_CREATE_RULESET_VERSION: Get the highest supported Landlock ABI 39*4b9c6d91SCole Faust * version. 40*4b9c6d91SCole Faust */ 41*4b9c6d91SCole Faust #ifndef LANDLOCK_CREATE_RULESET_VERSION 42*4b9c6d91SCole Faust #define LANDLOCK_CREATE_RULESET_VERSION (1U << 0) 43*4b9c6d91SCole Faust #endif 44*4b9c6d91SCole Faust 45*4b9c6d91SCole Faust /** 46*4b9c6d91SCole Faust * enum landlock_rule_type - Landlock rule type 47*4b9c6d91SCole Faust * 48*4b9c6d91SCole Faust * Argument of sys_landlock_add_rule(). 49*4b9c6d91SCole Faust */ 50*4b9c6d91SCole Faust enum minijail_landlock_rule_type { 51*4b9c6d91SCole Faust /** 52*4b9c6d91SCole Faust * @LANDLOCK_RULE_PATH_BENEATH: Type of a &struct 53*4b9c6d91SCole Faust * landlock_path_beneath_attr . 54*4b9c6d91SCole Faust */ 55*4b9c6d91SCole Faust LANDLOCK_RULE_PATH_BENEATH = 1, 56*4b9c6d91SCole Faust }; 57*4b9c6d91SCole Faust 58*4b9c6d91SCole Faust /** 59*4b9c6d91SCole Faust * struct landlock_path_beneath_attr - Path hierarchy definition 60*4b9c6d91SCole Faust * 61*4b9c6d91SCole Faust * Argument of sys_landlock_add_rule(). 62*4b9c6d91SCole Faust */ 63*4b9c6d91SCole Faust struct minijail_landlock_path_beneath_attr { 64*4b9c6d91SCole Faust /** 65*4b9c6d91SCole Faust * @allowed_access: Bitmask of allowed actions for this file hierarchy 66*4b9c6d91SCole Faust * (cf. `Filesystem flags`_). 67*4b9c6d91SCole Faust */ 68*4b9c6d91SCole Faust __u64 allowed_access; 69*4b9c6d91SCole Faust /** 70*4b9c6d91SCole Faust * @parent_fd: File descriptor, open with ``O_PATH``, which identifies 71*4b9c6d91SCole Faust * the parent directory of a file hierarchy, or just a file. 72*4b9c6d91SCole Faust */ 73*4b9c6d91SCole Faust __s32 parent_fd; 74*4b9c6d91SCole Faust /* 75*4b9c6d91SCole Faust * This struct is packed to avoid trailing reserved members. 76*4b9c6d91SCole Faust * Cf. security/landlock/syscalls.c:build_check_abi() 77*4b9c6d91SCole Faust */ 78*4b9c6d91SCole Faust } __attribute__((__packed__)); 79*4b9c6d91SCole Faust 80*4b9c6d91SCole Faust #ifndef LANDLOCK_ACCESS_FS_EXECUTE 81*4b9c6d91SCole Faust #define LANDLOCK_ACCESS_FS_EXECUTE (1ULL << 0) 82*4b9c6d91SCole Faust #endif 83*4b9c6d91SCole Faust 84*4b9c6d91SCole Faust #ifndef LANDLOCK_ACCESS_FS_WRITE_FILE 85*4b9c6d91SCole Faust #define LANDLOCK_ACCESS_FS_WRITE_FILE (1ULL << 1) 86*4b9c6d91SCole Faust #endif 87*4b9c6d91SCole Faust 88*4b9c6d91SCole Faust #ifndef LANDLOCK_ACCESS_FS_READ_FILE 89*4b9c6d91SCole Faust #define LANDLOCK_ACCESS_FS_READ_FILE (1ULL << 2) 90*4b9c6d91SCole Faust #endif 91*4b9c6d91SCole Faust 92*4b9c6d91SCole Faust #ifndef LANDLOCK_ACCESS_FS_READ_DIR 93*4b9c6d91SCole Faust #define LANDLOCK_ACCESS_FS_READ_DIR (1ULL << 3) 94*4b9c6d91SCole Faust #endif 95*4b9c6d91SCole Faust 96*4b9c6d91SCole Faust #ifndef LANDLOCK_ACCESS_FS_REMOVE_DIR 97*4b9c6d91SCole Faust #define LANDLOCK_ACCESS_FS_REMOVE_DIR (1ULL << 4) 98*4b9c6d91SCole Faust #endif 99*4b9c6d91SCole Faust 100*4b9c6d91SCole Faust #ifndef LANDLOCK_ACCESS_FS_REMOVE_FILE 101*4b9c6d91SCole Faust #define LANDLOCK_ACCESS_FS_REMOVE_FILE (1ULL << 5) 102*4b9c6d91SCole Faust #endif 103*4b9c6d91SCole Faust 104*4b9c6d91SCole Faust #ifndef LANDLOCK_ACCESS_FS_MAKE_CHAR 105*4b9c6d91SCole Faust #define LANDLOCK_ACCESS_FS_MAKE_CHAR (1ULL << 6) 106*4b9c6d91SCole Faust #endif 107*4b9c6d91SCole Faust 108*4b9c6d91SCole Faust #ifndef LANDLOCK_ACCESS_FS_MAKE_DIR 109*4b9c6d91SCole Faust #define LANDLOCK_ACCESS_FS_MAKE_DIR (1ULL << 7) 110*4b9c6d91SCole Faust #endif 111*4b9c6d91SCole Faust 112*4b9c6d91SCole Faust #ifndef LANDLOCK_ACCESS_FS_MAKE_REG 113*4b9c6d91SCole Faust #define LANDLOCK_ACCESS_FS_MAKE_REG (1ULL << 8) 114*4b9c6d91SCole Faust #endif 115*4b9c6d91SCole Faust 116*4b9c6d91SCole Faust #ifndef LANDLOCK_ACCESS_FS_MAKE_SOCK 117*4b9c6d91SCole Faust #define LANDLOCK_ACCESS_FS_MAKE_SOCK (1ULL << 9) 118*4b9c6d91SCole Faust #endif 119*4b9c6d91SCole Faust 120*4b9c6d91SCole Faust #ifndef LANDLOCK_ACCESS_FS_MAKE_FIFO 121*4b9c6d91SCole Faust #define LANDLOCK_ACCESS_FS_MAKE_FIFO (1ULL << 10) 122*4b9c6d91SCole Faust #endif 123*4b9c6d91SCole Faust 124*4b9c6d91SCole Faust #ifndef LANDLOCK_ACCESS_FS_MAKE_BLOCK 125*4b9c6d91SCole Faust #define LANDLOCK_ACCESS_FS_MAKE_BLOCK (1ULL << 11) 126*4b9c6d91SCole Faust #endif 127*4b9c6d91SCole Faust 128*4b9c6d91SCole Faust #ifndef LANDLOCK_ACCESS_FS_MAKE_SYM 129*4b9c6d91SCole Faust #define LANDLOCK_ACCESS_FS_MAKE_SYM (1ULL << 12) 130*4b9c6d91SCole Faust #endif 131*4b9c6d91SCole Faust 132*4b9c6d91SCole Faust #endif /* _LANDLOCK_H */ 133