1 #ifndef _LINUX_USER_NAMESPACE_H
2 #define _LINUX_USER_NAMESPACE_H
4 #include <linux/kref.h>
5 #include <linux/nsproxy.h>
6 #include <linux/ns_common.h>
7 #include <linux/sched.h>
10 #define UID_GID_MAP_MAX_EXTENTS 5
12 struct uid_gid_map { /* 64 bytes -- 1 cache line */
14 struct uid_gid_extent {
18 } extent[UID_GID_MAP_MAX_EXTENTS];
21 #define USERNS_SETGROUPS_ALLOWED 1UL
23 #define USERNS_INIT_FLAGS USERNS_SETGROUPS_ALLOWED
28 UCOUNT_USER_NAMESPACES,
29 UCOUNT_PID_NAMESPACES,
30 UCOUNT_UTS_NAMESPACES,
31 UCOUNT_IPC_NAMESPACES,
32 UCOUNT_CGROUP_NAMESPACES,
36 struct user_namespace {
37 struct uid_gid_map uid_map;
38 struct uid_gid_map gid_map;
39 struct uid_gid_map projid_map;
41 struct user_namespace *parent;
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;
53 struct work_struct work;
55 struct ctl_table_set set;
56 struct ctl_table_header *sysctls;
58 struct ucounts *ucounts;
59 int ucount_max[UCOUNT_COUNTS];
63 struct hlist_node node;
64 struct user_namespace *ns;
67 atomic_t ucount[UCOUNT_COUNTS];
70 extern struct user_namespace init_user_ns;
72 bool setup_userns_sysctls(struct user_namespace *ns);
73 void retire_userns_sysctls(struct user_namespace *ns);
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);
79 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
82 atomic_inc(&ns->count);
86 extern int create_user_ns(struct cred *new);
87 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
88 extern void __put_user_ns(struct user_namespace *ns);
90 static inline void put_user_ns(struct user_namespace *ns)
92 if (ns && atomic_dec_and_test(&ns->count))
96 struct seq_operations;
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;
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 *);
102 extern ssize_t proc_projid_map_write(struct file *, const char __user *, size_t, loff_t *);
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);
105 extern bool userns_may_setgroups(const struct user_namespace *ns);
106 extern bool current_in_userns(const struct user_namespace *target_ns);
109 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
111 return &init_user_ns;
114 static inline int create_user_ns(struct cred *new)
119 static inline int unshare_userns(unsigned long unshare_flags,
120 struct cred **new_cred)
122 if (unshare_flags & CLONE_NEWUSER)
127 static inline void put_user_ns(struct user_namespace *ns)
131 static inline bool userns_may_setgroups(const struct user_namespace *ns)
136 static inline bool current_in_userns(const struct user_namespace *target_ns)
142 #endif /* _LINUX_USER_H */