Blame view
include/linux/user_namespace.h
3.73 KB
acce292c8
|
1 2 3 4 5 |
#ifndef _LINUX_USER_NAMESPACE_H #define _LINUX_USER_NAMESPACE_H #include <linux/kref.h> #include <linux/nsproxy.h> |
435d5f4bb
|
6 |
#include <linux/ns_common.h> |
acce292c8
|
7 |
#include <linux/sched.h> |
77ec739d8
|
8 |
#include <linux/err.h> |
acce292c8
|
9 |
|
22d917d80
|
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
|
20 21 22 |
#define USERNS_SETGROUPS_ALLOWED 1UL #define USERNS_INIT_FLAGS USERNS_SETGROUPS_ALLOWED |
f6b2db1a3
|
23 |
struct ucounts; |
25f9c0817
|
24 25 26 |
enum ucount_type { UCOUNT_USER_NAMESPACES, |
f333c700c
|
27 |
UCOUNT_PID_NAMESPACES, |
f7af3d1c0
|
28 |
UCOUNT_UTS_NAMESPACES, |
aba356616
|
29 |
UCOUNT_IPC_NAMESPACES, |
703286608
|
30 |
UCOUNT_NET_NAMESPACES, |
537f7ccb3
|
31 |
UCOUNT_MNT_NAMESPACES, |
d08311dd6
|
32 |
UCOUNT_CGROUP_NAMESPACES, |
25f9c0817
|
33 34 |
UCOUNT_COUNTS, }; |
acce292c8
|
35 |
struct user_namespace { |
22d917d80
|
36 37 |
struct uid_gid_map uid_map; struct uid_gid_map gid_map; |
f76d207a6
|
38 |
struct uid_gid_map projid_map; |
c61a2810a
|
39 |
atomic_t count; |
aeb3ae9da
|
40 |
struct user_namespace *parent; |
8742f229b
|
41 |
int level; |
783291e69
|
42 43 |
kuid_t owner; kgid_t group; |
435d5f4bb
|
44 |
struct ns_common ns; |
9cc46516d
|
45 |
unsigned long flags; |
f36f8c75a
|
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
|
52 |
struct work_struct work; |
dbec28460
|
53 54 55 56 |
#ifdef CONFIG_SYSCTL struct ctl_table_set set; struct ctl_table_header *sysctls; #endif |
f6b2db1a3
|
57 |
struct ucounts *ucounts; |
25f9c0817
|
58 |
int ucount_max[UCOUNT_COUNTS]; |
f6b2db1a3
|
59 60 61 62 63 64 65 |
}; struct ucounts { struct hlist_node node; struct user_namespace *ns; kuid_t uid; atomic_t count; |
25f9c0817
|
66 |
atomic_t ucount[UCOUNT_COUNTS]; |
acce292c8
|
67 68 69 |
}; extern struct user_namespace init_user_ns; |
f6b2db1a3
|
70 71 72 |
bool setup_userns_sysctls(struct user_namespace *ns); void retire_userns_sysctls(struct user_namespace *ns); |
25f9c0817
|
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
|
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
|
81 |
atomic_inc(&ns->count); |
acce292c8
|
82 83 |
return ns; } |
18b6e0414
|
84 |
extern int create_user_ns(struct cred *new); |
b2e0d9870
|
85 |
extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred); |
b032132c3
|
86 |
extern void __put_user_ns(struct user_namespace *ns); |
acce292c8
|
87 88 89 |
static inline void put_user_ns(struct user_namespace *ns) { |
c61a2810a
|
90 |
if (ns && atomic_dec_and_test(&ns->count)) |
b032132c3
|
91 |
__put_user_ns(ns); |
acce292c8
|
92 |
} |
22d917d80
|
93 |
struct seq_operations; |
ccf94f1b4
|
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
|
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
|
99 |
extern ssize_t proc_projid_map_write(struct file *, const char __user *, size_t, loff_t *); |
9cc46516d
|
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
|
102 |
extern bool userns_may_setgroups(const struct user_namespace *ns); |
d07b846f6
|
103 |
extern bool current_in_userns(const struct user_namespace *target_ns); |
bcac25a58
|
104 105 |
struct ns_common *ns_get_owner(struct ns_common *ns); |
acce292c8
|
106 107 108 109 110 111 |
#else static inline struct user_namespace *get_user_ns(struct user_namespace *ns) { return &init_user_ns; } |
18b6e0414
|
112 |
static inline int create_user_ns(struct cred *new) |
acce292c8
|
113 |
{ |
18b6e0414
|
114 |
return -EINVAL; |
acce292c8
|
115 |
} |
b2e0d9870
|
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
|
123 124 125 |
static inline void put_user_ns(struct user_namespace *ns) { } |
273d2c67c
|
126 127 128 129 |
static inline bool userns_may_setgroups(const struct user_namespace *ns) { return true; } |
d07b846f6
|
130 131 132 133 134 |
static inline bool current_in_userns(const struct user_namespace *target_ns) { return true; } |
bcac25a58
|
135 136 137 138 139 |
static inline struct ns_common *ns_get_owner(struct ns_common *ns) { return ERR_PTR(-EPERM); } |
22d917d80
|
140 |
#endif |
acce292c8
|
141 |
#endif /* _LINUX_USER_H */ |