Merge tag 'media/v4.8-6' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab...
[linux-2.6-block.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
acce292c 25struct user_namespace {
22d917d8
EB
26 struct uid_gid_map uid_map;
27 struct uid_gid_map gid_map;
f76d207a 28 struct uid_gid_map projid_map;
c61a2810 29 atomic_t count;
aeb3ae9d 30 struct user_namespace *parent;
8742f229 31 int level;
783291e6
EB
32 kuid_t owner;
33 kgid_t group;
435d5f4b 34 struct ns_common ns;
9cc46516 35 unsigned long flags;
f36f8c75
DH
36
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;
41#endif
acce292c
CLG
42};
43
44extern struct user_namespace init_user_ns;
45
46#ifdef CONFIG_USER_NS
47
48static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
49{
50 if (ns)
c61a2810 51 atomic_inc(&ns->count);
acce292c
CLG
52 return ns;
53}
54
18b6e041 55extern int create_user_ns(struct cred *new);
b2e0d987 56extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
c61a2810 57extern void free_user_ns(struct user_namespace *ns);
acce292c
CLG
58
59static inline void put_user_ns(struct user_namespace *ns)
60{
c61a2810
EB
61 if (ns && atomic_dec_and_test(&ns->count))
62 free_user_ns(ns);
acce292c
CLG
63}
64
22d917d8 65struct seq_operations;
ccf94f1b
FF
66extern const struct seq_operations proc_uid_seq_operations;
67extern const struct seq_operations proc_gid_seq_operations;
68extern const struct seq_operations proc_projid_seq_operations;
22d917d8
EB
69extern ssize_t proc_uid_map_write(struct file *, const char __user *, size_t, loff_t *);
70extern ssize_t proc_gid_map_write(struct file *, const char __user *, size_t, loff_t *);
f76d207a 71extern ssize_t proc_projid_map_write(struct file *, const char __user *, size_t, loff_t *);
9cc46516
EB
72extern ssize_t proc_setgroups_write(struct file *, const char __user *, size_t, loff_t *);
73extern int proc_setgroups_show(struct seq_file *m, void *v);
273d2c67 74extern bool userns_may_setgroups(const struct user_namespace *ns);
d07b846f 75extern bool current_in_userns(const struct user_namespace *target_ns);
acce292c
CLG
76#else
77
78static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
79{
80 return &init_user_ns;
81}
82
18b6e041 83static inline int create_user_ns(struct cred *new)
acce292c 84{
18b6e041 85 return -EINVAL;
acce292c
CLG
86}
87
b2e0d987
EB
88static inline int unshare_userns(unsigned long unshare_flags,
89 struct cred **new_cred)
90{
91 if (unshare_flags & CLONE_NEWUSER)
92 return -EINVAL;
93 return 0;
94}
95
acce292c
CLG
96static inline void put_user_ns(struct user_namespace *ns)
97{
98}
99
273d2c67
EB
100static inline bool userns_may_setgroups(const struct user_namespace *ns)
101{
102 return true;
103}
d07b846f
SF
104
105static inline bool current_in_userns(const struct user_namespace *target_ns)
106{
107 return true;
108}
22d917d8
EB
109#endif
110
acce292c 111#endif /* _LINUX_USER_H */