Cleanup: Move instrumentation/ headers to include/instrumentation/
[lttng-modules.git] / wrapper / user_namespace.h
1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
3 * wrapper/user_namespace.h
4 *
5 * Copyright (C) 2019 Michael Jeanson <mjeanson@efficios.com>
6 *
7 */
8
9 #ifndef _LTTNG_WRAPPER_USER_NAMESPACE_H
10 #define _LTTNG_WRAPPER_USER_NAMESPACE_H
11
12 #include <linux/version.h>
13 #include <linux/user_namespace.h>
14
15
16 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)
17
18 #define lttng_current_xxuid(xxx) \
19 (from_kuid_munged(&init_user_ns, current_##xxx()))
20
21 #define lttng_current_vxxuid(xxx) \
22 (from_kuid_munged(current_user_ns(), current_##xxx()))
23
24 #define lttng_current_xxgid(xxx) \
25 (from_kgid_munged(&init_user_ns, current_##xxx()))
26
27 #define lttng_current_vxxgid(xxx) \
28 (from_kgid_munged(current_user_ns(), current_##xxx()))
29
30 static inline
31 uid_t lttng_task_vuid(struct task_struct *p, struct user_namespace *ns)
32 {
33 uid_t uid;
34 kuid_t kuid;
35
36 kuid = task_cred_xxx(p, uid);
37 uid = from_kuid_munged(ns, kuid);
38
39 return uid;
40 }
41
42 static inline
43 gid_t lttng_task_vgid(struct task_struct *p, struct user_namespace *ns)
44 {
45 gid_t gid;
46 kgid_t kgid;
47
48 kgid = task_cred_xxx(p, gid);
49 gid = from_kgid_munged(ns, kgid);
50
51 return gid;
52 }
53
54 #else
55
56 #define lttng_current_xxuid(xxx) (current_##xxx())
57
58 #define lttng_current_vxxuid(xxx) \
59 (user_ns_map_uid(current_user_ns(), current_cred(), current_##xxx()))
60
61 #define lttng_current_xxgid(xxx) (current_##xxx())
62
63 #define lttng_current_vxxgid(xxx) \
64 (user_ns_map_gid(current_user_ns(), current_cred(), current_##xxx()))
65
66 static inline
67 uid_t lttng_task_vuid(struct task_struct *p, struct user_namespace *ns)
68 {
69 uid_t uid;
70
71 /*
72 * __task_cred requires the RCU readlock be held
73 */
74 rcu_read_lock();
75 uid = user_ns_map_uid(ns, __task_cred(p), __task_cred(p)->uid);
76 rcu_read_unlock();
77
78 return uid;
79 }
80
81 static inline
82 gid_t lttng_task_vgid(struct task_struct *p, struct user_namespace *ns)
83 {
84 gid_t gid;
85
86 /*
87 * __task_cred requires the RCU readlock be held
88 */
89 rcu_read_lock();
90 gid = user_ns_map_gid(ns, __task_cred(p), __task_cred(p)->gid);
91 rcu_read_unlock();
92
93 return gid;
94 }
95
96 #endif
97
98 #define lttng_current_uid() (lttng_current_xxuid(uid))
99 #define lttng_current_euid() (lttng_current_xxuid(euid))
100 #define lttng_current_suid() (lttng_current_xxuid(suid))
101 #define lttng_current_fsuid() (lttng_current_xxuid(fsuid))
102 #define lttng_current_gid() (lttng_current_xxgid(gid))
103 #define lttng_current_egid() (lttng_current_xxgid(egid))
104 #define lttng_current_sgid() (lttng_current_xxgid(sgid))
105 #define lttng_current_fsgid() (lttng_current_xxgid(fsgid))
106
107 #define lttng_current_vuid() (lttng_current_vxxuid(uid))
108 #define lttng_current_veuid() (lttng_current_vxxuid(euid))
109 #define lttng_current_vsuid() (lttng_current_vxxuid(suid))
110 #define lttng_current_vfsuid() (lttng_current_vxxuid(fsuid))
111 #define lttng_current_vgid() (lttng_current_vxxgid(gid))
112 #define lttng_current_vegid() (lttng_current_vxxgid(egid))
113 #define lttng_current_vsgid() (lttng_current_vxxgid(sgid))
114 #define lttng_current_vfsgid() (lttng_current_vxxgid(fsgid))
115
116 #endif /* _LTTNG_WRAPPER_USER_NAMESPACE_H */
This page took 0.031296 seconds and 4 git commands to generate.