]>
Commit | Line | Data |
---|---|---|
acce292c CLG |
1 | #ifndef _LINUX_USER_NAMESPACE_H |
2 | #define _LINUX_USER_NAMESPACE_H | |
3 | ||
4 | #include <linux/kref.h> | |
5 | #include <linux/nsproxy.h> | |
435d5f4b | 6 | #include <linux/ns_common.h> |
acce292c | 7 | #include <linux/sched.h> |
77ec739d | 8 | #include <linux/err.h> |
acce292c | 9 | |
22d917d8 EB |
10 | #define UID_GID_MAP_MAX_EXTENTS 5 |
11 | ||
12 | struct uid_gid_map { /* 64 bytes -- 1 cache line */ | |
13 | u32 nr_extents; | |
14 | struct uid_gid_extent { | |
15 | u32 first; | |
16 | u32 lower_first; | |
17 | u32 count; | |
18 | } extent[UID_GID_MAP_MAX_EXTENTS]; | |
19 | }; | |
20 | ||
9cc46516 EB |
21 | #define USERNS_SETGROUPS_ALLOWED 1UL |
22 | ||
23 | #define USERNS_INIT_FLAGS USERNS_SETGROUPS_ALLOWED | |
24 | ||
f6b2db1a | 25 | struct ucounts; |
25f9c081 EB |
26 | |
27 | enum ucount_type { | |
28 | UCOUNT_USER_NAMESPACES, | |
f333c700 | 29 | UCOUNT_PID_NAMESPACES, |
f7af3d1c | 30 | UCOUNT_UTS_NAMESPACES, |
aba35661 | 31 | UCOUNT_IPC_NAMESPACES, |
d08311dd | 32 | UCOUNT_CGROUP_NAMESPACES, |
25f9c081 EB |
33 | UCOUNT_COUNTS, |
34 | }; | |
35 | ||
acce292c | 36 | struct user_namespace { |
22d917d8 EB |
37 | struct uid_gid_map uid_map; |
38 | struct uid_gid_map gid_map; | |
f76d207a | 39 | struct uid_gid_map projid_map; |
c61a2810 | 40 | atomic_t count; |
aeb3ae9d | 41 | struct user_namespace *parent; |
8742f229 | 42 | int level; |
783291e6 EB |
43 | kuid_t owner; |
44 | kgid_t group; | |
435d5f4b | 45 | struct ns_common ns; |
9cc46516 | 46 | unsigned long flags; |
f36f8c75 DH |
47 | |
48 | /* Register of per-UID persistent keyrings for this namespace */ | |
49 | #ifdef CONFIG_PERSISTENT_KEYRINGS | |
50 | struct key *persistent_keyring_register; | |
51 | struct rw_semaphore persistent_keyring_register_sem; | |
52 | #endif | |
b032132c | 53 | struct work_struct work; |
dbec2846 EB |
54 | #ifdef CONFIG_SYSCTL |
55 | struct ctl_table_set set; | |
56 | struct ctl_table_header *sysctls; | |
57 | #endif | |
f6b2db1a | 58 | struct ucounts *ucounts; |
25f9c081 | 59 | int ucount_max[UCOUNT_COUNTS]; |
f6b2db1a EB |
60 | }; |
61 | ||
62 | struct ucounts { | |
63 | struct hlist_node node; | |
64 | struct user_namespace *ns; | |
65 | kuid_t uid; | |
66 | atomic_t count; | |
25f9c081 | 67 | atomic_t ucount[UCOUNT_COUNTS]; |
acce292c CLG |
68 | }; |
69 | ||
70 | extern struct user_namespace init_user_ns; | |
f6b2db1a EB |
71 | |
72 | bool setup_userns_sysctls(struct user_namespace *ns); | |
73 | void retire_userns_sysctls(struct user_namespace *ns); | |
25f9c081 EB |
74 | struct ucounts *inc_ucount(struct user_namespace *ns, kuid_t uid, enum ucount_type type); |
75 | void dec_ucount(struct ucounts *ucounts, enum ucount_type type); | |
acce292c CLG |
76 | |
77 | #ifdef CONFIG_USER_NS | |
78 | ||
79 | static inline struct user_namespace *get_user_ns(struct user_namespace *ns) | |
80 | { | |
81 | if (ns) | |
c61a2810 | 82 | atomic_inc(&ns->count); |
acce292c CLG |
83 | return ns; |
84 | } | |
85 | ||
18b6e041 | 86 | extern int create_user_ns(struct cred *new); |
b2e0d987 | 87 | extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred); |
b032132c | 88 | extern void __put_user_ns(struct user_namespace *ns); |
acce292c CLG |
89 | |
90 | static inline void put_user_ns(struct user_namespace *ns) | |
91 | { | |
c61a2810 | 92 | if (ns && atomic_dec_and_test(&ns->count)) |
b032132c | 93 | __put_user_ns(ns); |
acce292c CLG |
94 | } |
95 | ||
22d917d8 | 96 | struct seq_operations; |
ccf94f1b FF |
97 | extern const struct seq_operations proc_uid_seq_operations; |
98 | extern const struct seq_operations proc_gid_seq_operations; | |
99 | extern const struct seq_operations proc_projid_seq_operations; | |
22d917d8 EB |
100 | extern ssize_t proc_uid_map_write(struct file *, const char __user *, size_t, loff_t *); |
101 | extern ssize_t proc_gid_map_write(struct file *, const char __user *, size_t, loff_t *); | |
f76d207a | 102 | extern ssize_t proc_projid_map_write(struct file *, const char __user *, size_t, loff_t *); |
9cc46516 EB |
103 | extern ssize_t proc_setgroups_write(struct file *, const char __user *, size_t, loff_t *); |
104 | extern int proc_setgroups_show(struct seq_file *m, void *v); | |
273d2c67 | 105 | extern bool userns_may_setgroups(const struct user_namespace *ns); |
d07b846f | 106 | extern bool current_in_userns(const struct user_namespace *target_ns); |
acce292c CLG |
107 | #else |
108 | ||
109 | static inline struct user_namespace *get_user_ns(struct user_namespace *ns) | |
110 | { | |
111 | return &init_user_ns; | |
112 | } | |
113 | ||
18b6e041 | 114 | static inline int create_user_ns(struct cred *new) |
acce292c | 115 | { |
18b6e041 | 116 | return -EINVAL; |
acce292c CLG |
117 | } |
118 | ||
b2e0d987 EB |
119 | static inline int unshare_userns(unsigned long unshare_flags, |
120 | struct cred **new_cred) | |
121 | { | |
122 | if (unshare_flags & CLONE_NEWUSER) | |
123 | return -EINVAL; | |
124 | return 0; | |
125 | } | |
126 | ||
acce292c CLG |
127 | static inline void put_user_ns(struct user_namespace *ns) |
128 | { | |
129 | } | |
130 | ||
273d2c67 EB |
131 | static inline bool userns_may_setgroups(const struct user_namespace *ns) |
132 | { | |
133 | return true; | |
134 | } | |
d07b846f SF |
135 | |
136 | static inline bool current_in_userns(const struct user_namespace *target_ns) | |
137 | { | |
138 | return true; | |
139 | } | |
22d917d8 EB |
140 | #endif |
141 | ||
acce292c | 142 | #endif /* _LINUX_USER_H */ |