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