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
25 struct user_namespace
{
26 struct uid_gid_map uid_map
;
27 struct uid_gid_map gid_map
;
28 struct uid_gid_map projid_map
;
30 struct user_namespace
*parent
;
37 /* Register of per-UID persistent keyrings for this namespace */
38 #ifdef CONFIG_PERSISTENT_KEYRINGS
39 struct key
*persistent_keyring_register
;
40 struct rw_semaphore persistent_keyring_register_sem
;
44 extern struct user_namespace init_user_ns
;
48 static inline struct user_namespace
*get_user_ns(struct user_namespace
*ns
)
51 atomic_inc(&ns
->count
);
55 extern int create_user_ns(struct cred
*new);
56 extern int unshare_userns(unsigned long unshare_flags
, struct cred
**new_cred
);
57 extern void free_user_ns(struct user_namespace
*ns
);
59 static inline void put_user_ns(struct user_namespace
*ns
)
61 if (ns
&& atomic_dec_and_test(&ns
->count
))
65 struct seq_operations
;
66 extern const struct seq_operations proc_uid_seq_operations
;
67 extern const struct seq_operations proc_gid_seq_operations
;
68 extern const struct seq_operations proc_projid_seq_operations
;
69 extern ssize_t
proc_uid_map_write(struct file
*, const char __user
*, size_t, loff_t
*);
70 extern ssize_t
proc_gid_map_write(struct file
*, const char __user
*, size_t, loff_t
*);
71 extern ssize_t
proc_projid_map_write(struct file
*, const char __user
*, size_t, loff_t
*);
72 extern ssize_t
proc_setgroups_write(struct file
*, const char __user
*, size_t, loff_t
*);
73 extern int proc_setgroups_show(struct seq_file
*m
, void *v
);
74 extern bool userns_may_setgroups(const struct user_namespace
*ns
);
77 static inline struct user_namespace
*get_user_ns(struct user_namespace
*ns
)
82 static inline int create_user_ns(struct cred
*new)
87 static inline int unshare_userns(unsigned long unshare_flags
,
88 struct cred
**new_cred
)
90 if (unshare_flags
& CLONE_NEWUSER
)
95 static inline void put_user_ns(struct user_namespace
*ns
)
99 static inline bool userns_may_setgroups(const struct user_namespace
*ns
)
105 #endif /* _LINUX_USER_H */