Blame view

include/linux/user_namespace.h 3.73 KB
acce292c8   Cedric Le Goater   user namespace: a...
1
2
3
4
5
  #ifndef _LINUX_USER_NAMESPACE_H
  #define _LINUX_USER_NAMESPACE_H
  
  #include <linux/kref.h>
  #include <linux/nsproxy.h>
435d5f4bb   Al Viro   common object emb...
6
  #include <linux/ns_common.h>
acce292c8   Cedric Le Goater   user namespace: a...
7
  #include <linux/sched.h>
77ec739d8   Serge E. Hallyn   user namespace: a...
8
  #include <linux/err.h>
acce292c8   Cedric Le Goater   user namespace: a...
9

22d917d80   Eric W. Biederman   userns: Rework th...
10
11
12
13
14
15
16
17
18
19
  #define UID_GID_MAP_MAX_EXTENTS 5
  
  struct uid_gid_map {	/* 64 bytes -- 1 cache line */
  	u32 nr_extents;
  	struct uid_gid_extent {
  		u32 first;
  		u32 lower_first;
  		u32 count;
  	} extent[UID_GID_MAP_MAX_EXTENTS];
  };
9cc46516d   Eric W. Biederman   userns: Add a kno...
20
21
22
  #define USERNS_SETGROUPS_ALLOWED 1UL
  
  #define USERNS_INIT_FLAGS USERNS_SETGROUPS_ALLOWED
f6b2db1a3   Eric W. Biederman   userns: Make the ...
23
  struct ucounts;
25f9c0817   Eric W. Biederman   userns: Generaliz...
24
25
26
  
  enum ucount_type {
  	UCOUNT_USER_NAMESPACES,
f333c700c   Eric W. Biederman   pidns: Add a limi...
27
  	UCOUNT_PID_NAMESPACES,
f7af3d1c0   Eric W. Biederman   utsns: Add a limi...
28
  	UCOUNT_UTS_NAMESPACES,
aba356616   Eric W. Biederman   ipcns: Add a lim...
29
  	UCOUNT_IPC_NAMESPACES,
703286608   Eric W. Biederman   netns: Add a limi...
30
  	UCOUNT_NET_NAMESPACES,
537f7ccb3   Eric W. Biederman   mntns: Add a limi...
31
  	UCOUNT_MNT_NAMESPACES,
d08311dd6   Eric W. Biederman   cgroupns: Add a l...
32
  	UCOUNT_CGROUP_NAMESPACES,
25f9c0817   Eric W. Biederman   userns: Generaliz...
33
34
  	UCOUNT_COUNTS,
  };
acce292c8   Cedric Le Goater   user namespace: a...
35
  struct user_namespace {
22d917d80   Eric W. Biederman   userns: Rework th...
36
37
  	struct uid_gid_map	uid_map;
  	struct uid_gid_map	gid_map;
f76d207a6   Eric W. Biederman   userns: Add kproj...
38
  	struct uid_gid_map	projid_map;
c61a2810a   Eric W. Biederman   userns: Avoid rec...
39
  	atomic_t		count;
aeb3ae9da   Eric W. Biederman   userns: Add an ex...
40
  	struct user_namespace	*parent;
8742f229b   Oleg Nesterov   userns: limit the...
41
  	int			level;
783291e69   Eric W. Biederman   userns: Simplify ...
42
43
  	kuid_t			owner;
  	kgid_t			group;
435d5f4bb   Al Viro   common object emb...
44
  	struct ns_common	ns;
9cc46516d   Eric W. Biederman   userns: Add a kno...
45
  	unsigned long		flags;
f36f8c75a   David Howells   KEYS: Add per-use...
46
47
48
49
50
51
  
  	/* Register of per-UID persistent keyrings for this namespace */
  #ifdef CONFIG_PERSISTENT_KEYRINGS
  	struct key		*persistent_keyring_register;
  	struct rw_semaphore	persistent_keyring_register_sem;
  #endif
b032132c3   Eric W. Biederman   userns: Free user...
52
  	struct work_struct	work;
dbec28460   Eric W. Biederman   userns: Add per u...
53
54
55
56
  #ifdef CONFIG_SYSCTL
  	struct ctl_table_set	set;
  	struct ctl_table_header *sysctls;
  #endif
f6b2db1a3   Eric W. Biederman   userns: Make the ...
57
  	struct ucounts		*ucounts;
25f9c0817   Eric W. Biederman   userns: Generaliz...
58
  	int ucount_max[UCOUNT_COUNTS];
f6b2db1a3   Eric W. Biederman   userns: Make the ...
59
60
61
62
63
64
65
  };
  
  struct ucounts {
  	struct hlist_node node;
  	struct user_namespace *ns;
  	kuid_t uid;
  	atomic_t count;
25f9c0817   Eric W. Biederman   userns: Generaliz...
66
  	atomic_t ucount[UCOUNT_COUNTS];
acce292c8   Cedric Le Goater   user namespace: a...
67
68
69
  };
  
  extern struct user_namespace init_user_ns;
f6b2db1a3   Eric W. Biederman   userns: Make the ...
70
71
72
  
  bool setup_userns_sysctls(struct user_namespace *ns);
  void retire_userns_sysctls(struct user_namespace *ns);
25f9c0817   Eric W. Biederman   userns: Generaliz...
73
74
  struct ucounts *inc_ucount(struct user_namespace *ns, kuid_t uid, enum ucount_type type);
  void dec_ucount(struct ucounts *ucounts, enum ucount_type type);
acce292c8   Cedric Le Goater   user namespace: a...
75
76
77
78
79
80
  
  #ifdef CONFIG_USER_NS
  
  static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
  {
  	if (ns)
c61a2810a   Eric W. Biederman   userns: Avoid rec...
81
  		atomic_inc(&ns->count);
acce292c8   Cedric Le Goater   user namespace: a...
82
83
  	return ns;
  }
18b6e0414   Serge Hallyn   User namespaces: ...
84
  extern int create_user_ns(struct cred *new);
b2e0d9870   Eric W. Biederman   userns: Implement...
85
  extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
b032132c3   Eric W. Biederman   userns: Free user...
86
  extern void __put_user_ns(struct user_namespace *ns);
acce292c8   Cedric Le Goater   user namespace: a...
87
88
89
  
  static inline void put_user_ns(struct user_namespace *ns)
  {
c61a2810a   Eric W. Biederman   userns: Avoid rec...
90
  	if (ns && atomic_dec_and_test(&ns->count))
b032132c3   Eric W. Biederman   userns: Free user...
91
  		__put_user_ns(ns);
acce292c8   Cedric Le Goater   user namespace: a...
92
  }
22d917d80   Eric W. Biederman   userns: Rework th...
93
  struct seq_operations;
ccf94f1b4   Fabian Frederick   proc: constify se...
94
95
96
  extern const struct seq_operations proc_uid_seq_operations;
  extern const struct seq_operations proc_gid_seq_operations;
  extern const struct seq_operations proc_projid_seq_operations;
22d917d80   Eric W. Biederman   userns: Rework th...
97
98
  extern ssize_t proc_uid_map_write(struct file *, const char __user *, size_t, loff_t *);
  extern ssize_t proc_gid_map_write(struct file *, const char __user *, size_t, loff_t *);
f76d207a6   Eric W. Biederman   userns: Add kproj...
99
  extern ssize_t proc_projid_map_write(struct file *, const char __user *, size_t, loff_t *);
9cc46516d   Eric W. Biederman   userns: Add a kno...
100
101
  extern ssize_t proc_setgroups_write(struct file *, const char __user *, size_t, loff_t *);
  extern int proc_setgroups_show(struct seq_file *m, void *v);
273d2c67c   Eric W. Biederman   userns: Don't all...
102
  extern bool userns_may_setgroups(const struct user_namespace *ns);
d07b846f6   Seth Forshee   fs: Limit file ca...
103
  extern bool current_in_userns(const struct user_namespace *target_ns);
bcac25a58   Andrey Vagin   kernel: add a hel...
104
105
  
  struct ns_common *ns_get_owner(struct ns_common *ns);
acce292c8   Cedric Le Goater   user namespace: a...
106
107
108
109
110
111
  #else
  
  static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
  {
  	return &init_user_ns;
  }
18b6e0414   Serge Hallyn   User namespaces: ...
112
  static inline int create_user_ns(struct cred *new)
acce292c8   Cedric Le Goater   user namespace: a...
113
  {
18b6e0414   Serge Hallyn   User namespaces: ...
114
  	return -EINVAL;
acce292c8   Cedric Le Goater   user namespace: a...
115
  }
b2e0d9870   Eric W. Biederman   userns: Implement...
116
117
118
119
120
121
122
  static inline int unshare_userns(unsigned long unshare_flags,
  				 struct cred **new_cred)
  {
  	if (unshare_flags & CLONE_NEWUSER)
  		return -EINVAL;
  	return 0;
  }
acce292c8   Cedric Le Goater   user namespace: a...
123
124
125
  static inline void put_user_ns(struct user_namespace *ns)
  {
  }
273d2c67c   Eric W. Biederman   userns: Don't all...
126
127
128
129
  static inline bool userns_may_setgroups(const struct user_namespace *ns)
  {
  	return true;
  }
d07b846f6   Seth Forshee   fs: Limit file ca...
130
131
132
133
134
  
  static inline bool current_in_userns(const struct user_namespace *target_ns)
  {
  	return true;
  }
bcac25a58   Andrey Vagin   kernel: add a hel...
135
136
137
138
139
  
  static inline struct ns_common *ns_get_owner(struct ns_common *ns)
  {
  	return ERR_PTR(-EPERM);
  }
22d917d80   Eric W. Biederman   userns: Rework th...
140
  #endif
acce292c8   Cedric Le Goater   user namespace: a...
141
  #endif /* _LINUX_USER_H */