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