1 /* SPDX-License-Identifier: GPL-2.0 */ << 2 #ifndef _LINUX_PROJID_H 1 #ifndef _LINUX_PROJID_H 3 #define _LINUX_PROJID_H 2 #define _LINUX_PROJID_H 4 3 5 /* 4 /* 6 * A set of types for the internal kernel type 5 * A set of types for the internal kernel types representing project ids. 7 * 6 * 8 * The types defined in this header allow dist 7 * The types defined in this header allow distinguishing which project ids in 9 * the kernel are values used by userspace and 8 * the kernel are values used by userspace and which project id values are 10 * the internal kernel values. With the addit 9 * the internal kernel values. With the addition of user namespaces the values 11 * can be different. Using the type system ma 10 * can be different. Using the type system makes it possible for the compiler 12 * to detect when we overlook these difference 11 * to detect when we overlook these differences. 13 * 12 * 14 */ 13 */ 15 #include <linux/types.h> 14 #include <linux/types.h> 16 15 17 struct user_namespace; 16 struct user_namespace; 18 extern struct user_namespace init_user_ns; 17 extern struct user_namespace init_user_ns; 19 18 20 typedef __kernel_uid32_t projid_t; 19 typedef __kernel_uid32_t projid_t; 21 20 >> 21 #ifdef CONFIG_UIDGID_STRICT_TYPE_CHECKS >> 22 22 typedef struct { 23 typedef struct { 23 projid_t val; 24 projid_t val; 24 } kprojid_t; 25 } kprojid_t; 25 26 26 static inline projid_t __kprojid_val(kprojid_t 27 static inline projid_t __kprojid_val(kprojid_t projid) 27 { 28 { 28 return projid.val; 29 return projid.val; 29 } 30 } 30 31 31 #define KPROJIDT_INIT(value) (kprojid_t){ valu 32 #define KPROJIDT_INIT(value) (kprojid_t){ value } >> 33 >> 34 #else >> 35 >> 36 typedef projid_t kprojid_t; >> 37 >> 38 static inline projid_t __kprojid_val(kprojid_t projid) >> 39 { >> 40 return projid; >> 41 } >> 42 >> 43 #define KPROJIDT_INIT(value) ((kprojid_t) value ) >> 44 >> 45 #endif 32 46 33 #define INVALID_PROJID KPROJIDT_INIT(-1) 47 #define INVALID_PROJID KPROJIDT_INIT(-1) 34 #define OVERFLOW_PROJID 65534 48 #define OVERFLOW_PROJID 65534 35 49 36 static inline bool projid_eq(kprojid_t left, k 50 static inline bool projid_eq(kprojid_t left, kprojid_t right) 37 { 51 { 38 return __kprojid_val(left) == __kproji 52 return __kprojid_val(left) == __kprojid_val(right); 39 } 53 } 40 54 41 static inline bool projid_lt(kprojid_t left, k 55 static inline bool projid_lt(kprojid_t left, kprojid_t right) 42 { 56 { 43 return __kprojid_val(left) < __kprojid 57 return __kprojid_val(left) < __kprojid_val(right); 44 } 58 } 45 59 46 static inline bool projid_valid(kprojid_t proj 60 static inline bool projid_valid(kprojid_t projid) 47 { 61 { 48 return !projid_eq(projid, INVALID_PROJ 62 return !projid_eq(projid, INVALID_PROJID); 49 } 63 } 50 64 51 #ifdef CONFIG_USER_NS 65 #ifdef CONFIG_USER_NS 52 66 53 extern kprojid_t make_kprojid(struct user_name 67 extern kprojid_t make_kprojid(struct user_namespace *from, projid_t projid); 54 68 55 extern projid_t from_kprojid(struct user_names 69 extern projid_t from_kprojid(struct user_namespace *to, kprojid_t projid); 56 extern projid_t from_kprojid_munged(struct use 70 extern projid_t from_kprojid_munged(struct user_namespace *to, kprojid_t projid); 57 71 58 static inline bool kprojid_has_mapping(struct 72 static inline bool kprojid_has_mapping(struct user_namespace *ns, kprojid_t projid) 59 { 73 { 60 return from_kprojid(ns, projid) != (pr 74 return from_kprojid(ns, projid) != (projid_t)-1; 61 } 75 } 62 76 63 #else 77 #else 64 78 65 static inline kprojid_t make_kprojid(struct us 79 static inline kprojid_t make_kprojid(struct user_namespace *from, projid_t projid) 66 { 80 { 67 return KPROJIDT_INIT(projid); 81 return KPROJIDT_INIT(projid); 68 } 82 } 69 83 70 static inline projid_t from_kprojid(struct use 84 static inline projid_t from_kprojid(struct user_namespace *to, kprojid_t kprojid) 71 { 85 { 72 return __kprojid_val(kprojid); 86 return __kprojid_val(kprojid); 73 } 87 } 74 88 75 static inline projid_t from_kprojid_munged(str 89 static inline projid_t from_kprojid_munged(struct user_namespace *to, kprojid_t kprojid) 76 { 90 { 77 projid_t projid = from_kprojid(to, kpr 91 projid_t projid = from_kprojid(to, kprojid); 78 if (projid == (projid_t)-1) 92 if (projid == (projid_t)-1) 79 projid = OVERFLOW_PROJID; 93 projid = OVERFLOW_PROJID; 80 return projid; 94 return projid; 81 } 95 } 82 96 83 static inline bool kprojid_has_mapping(struct 97 static inline bool kprojid_has_mapping(struct user_namespace *ns, kprojid_t projid) 84 { 98 { 85 return true; 99 return true; 86 } 100 } 87 101 88 #endif /* CONFIG_USER_NS */ 102 #endif /* CONFIG_USER_NS */ 89 103 90 #endif /* _LINUX_PROJID_H */ 104 #endif /* _LINUX_PROJID_H */ 91 105
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.