Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or |
| 3 | * modify it under the terms of the GNU General Public License as |
| 4 | * published by the Free Software Foundation, version 2 of the |
| 5 | * License. |
| 6 | */ |
| 7 | |
Paul Gortmaker | 9984de1 | 2011-05-23 14:51:41 -0400 | [diff] [blame] | 8 | #include <linux/export.h> |
Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 9 | #include <linux/nsproxy.h> |
Robert P. J. Day | 1aeb272 | 2008-04-29 00:59:25 -0700 | [diff] [blame] | 10 | #include <linux/slab.h> |
Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 11 | #include <linux/user_namespace.h> |
Eric W. Biederman | cde1975 | 2012-07-26 06:24:06 -0700 | [diff] [blame] | 12 | #include <linux/proc_fs.h> |
Eric W. Biederman | 5c1469d | 2010-06-13 03:28:03 +0000 | [diff] [blame] | 13 | #include <linux/highuid.h> |
Serge Hallyn | 18b6e04 | 2008-10-15 16:38:45 -0500 | [diff] [blame] | 14 | #include <linux/cred.h> |
Eric W. Biederman | 973c591 | 2011-11-17 01:59:07 -0800 | [diff] [blame] | 15 | #include <linux/securebits.h> |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 16 | #include <linux/keyctl.h> |
| 17 | #include <linux/key-type.h> |
| 18 | #include <keys/user-type.h> |
| 19 | #include <linux/seq_file.h> |
| 20 | #include <linux/fs.h> |
| 21 | #include <linux/uaccess.h> |
| 22 | #include <linux/ctype.h> |
Eric W. Biederman | f76d207 | 2012-08-30 01:24:05 -0700 | [diff] [blame] | 23 | #include <linux/projid.h> |
Eric W. Biederman | e66eded | 2013-03-13 11:51:49 -0700 | [diff] [blame] | 24 | #include <linux/fs_struct.h> |
Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 25 | |
Pavel Emelyanov | 6164281 | 2011-01-12 17:00:46 -0800 | [diff] [blame] | 26 | static struct kmem_cache *user_ns_cachep __read_mostly; |
| 27 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 28 | static bool new_idmap_permitted(struct user_namespace *ns, int cap_setid, |
| 29 | struct uid_gid_map *map); |
| 30 | |
Eric W. Biederman | cde1975 | 2012-07-26 06:24:06 -0700 | [diff] [blame] | 31 | static void set_cred_user_ns(struct cred *cred, struct user_namespace *user_ns) |
| 32 | { |
| 33 | /* Start with the same capabilities as init but useless for doing |
| 34 | * anything as the capabilities are bound to the new user namespace. |
| 35 | */ |
| 36 | cred->securebits = SECUREBITS_DEFAULT; |
| 37 | cred->cap_inheritable = CAP_EMPTY_SET; |
| 38 | cred->cap_permitted = CAP_FULL_SET; |
| 39 | cred->cap_effective = CAP_FULL_SET; |
| 40 | cred->cap_bset = CAP_FULL_SET; |
| 41 | #ifdef CONFIG_KEYS |
| 42 | key_put(cred->request_key_auth); |
| 43 | cred->request_key_auth = NULL; |
| 44 | #endif |
| 45 | /* tgcred will be cleared in our caller bc CLONE_THREAD won't be set */ |
| 46 | cred->user_ns = user_ns; |
| 47 | } |
| 48 | |
Serge E. Hallyn | 77ec739 | 2007-07-15 23:41:01 -0700 | [diff] [blame] | 49 | /* |
Serge Hallyn | 18b6e04 | 2008-10-15 16:38:45 -0500 | [diff] [blame] | 50 | * Create a new user namespace, deriving the creator from the user in the |
| 51 | * passed credentials, and replacing that user with the new root user for the |
| 52 | * new namespace. |
| 53 | * |
| 54 | * This is called by copy_creds(), which will finish setting the target task's |
| 55 | * credentials. |
Serge E. Hallyn | 77ec739 | 2007-07-15 23:41:01 -0700 | [diff] [blame] | 56 | */ |
Serge Hallyn | 18b6e04 | 2008-10-15 16:38:45 -0500 | [diff] [blame] | 57 | int create_user_ns(struct cred *new) |
Serge E. Hallyn | 77ec739 | 2007-07-15 23:41:01 -0700 | [diff] [blame] | 58 | { |
Eric W. Biederman | 0093ccb | 2011-11-16 21:52:53 -0800 | [diff] [blame] | 59 | struct user_namespace *ns, *parent_ns = new->user_ns; |
Eric W. Biederman | 078de5f | 2012-02-08 07:00:08 -0800 | [diff] [blame] | 60 | kuid_t owner = new->euid; |
| 61 | kgid_t group = new->egid; |
Eric W. Biederman | 98f842e | 2011-06-15 10:21:48 -0700 | [diff] [blame] | 62 | int ret; |
Eric W. Biederman | 783291e | 2011-11-17 01:32:59 -0800 | [diff] [blame] | 63 | |
Eric W. Biederman | 3151527 | 2013-03-15 01:45:51 -0700 | [diff] [blame] | 64 | /* |
| 65 | * Verify that we can not violate the policy of which files |
| 66 | * may be accessed that is specified by the root directory, |
| 67 | * by verifing that the root directory is at the root of the |
| 68 | * mount namespace which allows all files to be accessed. |
| 69 | */ |
| 70 | if (current_chrooted()) |
| 71 | return -EPERM; |
| 72 | |
Eric W. Biederman | 783291e | 2011-11-17 01:32:59 -0800 | [diff] [blame] | 73 | /* The creator needs a mapping in the parent user namespace |
| 74 | * or else we won't be able to reasonably tell userspace who |
| 75 | * created a user_namespace. |
| 76 | */ |
| 77 | if (!kuid_has_mapping(parent_ns, owner) || |
| 78 | !kgid_has_mapping(parent_ns, group)) |
| 79 | return -EPERM; |
Serge E. Hallyn | 77ec739 | 2007-07-15 23:41:01 -0700 | [diff] [blame] | 80 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 81 | ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL); |
Serge E. Hallyn | 77ec739 | 2007-07-15 23:41:01 -0700 | [diff] [blame] | 82 | if (!ns) |
Serge Hallyn | 18b6e04 | 2008-10-15 16:38:45 -0500 | [diff] [blame] | 83 | return -ENOMEM; |
Serge E. Hallyn | 77ec739 | 2007-07-15 23:41:01 -0700 | [diff] [blame] | 84 | |
Eric W. Biederman | 98f842e | 2011-06-15 10:21:48 -0700 | [diff] [blame] | 85 | ret = proc_alloc_inum(&ns->proc_inum); |
| 86 | if (ret) { |
| 87 | kmem_cache_free(user_ns_cachep, ns); |
| 88 | return ret; |
| 89 | } |
| 90 | |
Eric W. Biederman | c61a281 | 2012-12-28 18:58:39 -0800 | [diff] [blame] | 91 | atomic_set(&ns->count, 1); |
Eric W. Biederman | cde1975 | 2012-07-26 06:24:06 -0700 | [diff] [blame] | 92 | /* Leave the new->user_ns reference with the new user namespace. */ |
Eric W. Biederman | aeb3ae9 | 2011-11-16 21:59:43 -0800 | [diff] [blame] | 93 | ns->parent = parent_ns; |
Eric W. Biederman | 783291e | 2011-11-17 01:32:59 -0800 | [diff] [blame] | 94 | ns->owner = owner; |
| 95 | ns->group = group; |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 96 | |
Eric W. Biederman | cde1975 | 2012-07-26 06:24:06 -0700 | [diff] [blame] | 97 | set_cred_user_ns(new, ns); |
Eric W. Biederman | 0093ccb | 2011-11-16 21:52:53 -0800 | [diff] [blame] | 98 | |
Eric W. Biederman | 87a8ebd | 2013-03-24 14:28:27 -0700 | [diff] [blame] | 99 | update_mnt_policy(ns); |
| 100 | |
Serge Hallyn | 18b6e04 | 2008-10-15 16:38:45 -0500 | [diff] [blame] | 101 | return 0; |
Cedric Le Goater | acce292 | 2007-07-15 23:40:59 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Eric W. Biederman | b2e0d987 | 2012-07-26 05:15:35 -0700 | [diff] [blame] | 104 | int unshare_userns(unsigned long unshare_flags, struct cred **new_cred) |
| 105 | { |
| 106 | struct cred *cred; |
| 107 | |
| 108 | if (!(unshare_flags & CLONE_NEWUSER)) |
| 109 | return 0; |
| 110 | |
| 111 | cred = prepare_creds(); |
| 112 | if (!cred) |
| 113 | return -ENOMEM; |
| 114 | |
| 115 | *new_cred = cred; |
| 116 | return create_user_ns(cred); |
| 117 | } |
| 118 | |
Eric W. Biederman | c61a281 | 2012-12-28 18:58:39 -0800 | [diff] [blame] | 119 | void free_user_ns(struct user_namespace *ns) |
David Howells | 5170836 | 2009-02-27 14:03:03 -0800 | [diff] [blame] | 120 | { |
Eric W. Biederman | c61a281 | 2012-12-28 18:58:39 -0800 | [diff] [blame] | 121 | struct user_namespace *parent; |
David Howells | 5170836 | 2009-02-27 14:03:03 -0800 | [diff] [blame] | 122 | |
Eric W. Biederman | c61a281 | 2012-12-28 18:58:39 -0800 | [diff] [blame] | 123 | do { |
| 124 | parent = ns->parent; |
| 125 | proc_free_inum(ns->proc_inum); |
| 126 | kmem_cache_free(user_ns_cachep, ns); |
| 127 | ns = parent; |
| 128 | } while (atomic_dec_and_test(&parent->count)); |
David Howells | 5170836 | 2009-02-27 14:03:03 -0800 | [diff] [blame] | 129 | } |
Michael Halcrow | 6a3fd92 | 2008-04-29 00:59:52 -0700 | [diff] [blame] | 130 | EXPORT_SYMBOL(free_user_ns); |
Eric W. Biederman | 5c1469d | 2010-06-13 03:28:03 +0000 | [diff] [blame] | 131 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 132 | static u32 map_id_range_down(struct uid_gid_map *map, u32 id, u32 count) |
Eric W. Biederman | 5c1469d | 2010-06-13 03:28:03 +0000 | [diff] [blame] | 133 | { |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 134 | unsigned idx, extents; |
| 135 | u32 first, last, id2; |
Eric W. Biederman | 5c1469d | 2010-06-13 03:28:03 +0000 | [diff] [blame] | 136 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 137 | id2 = id + count - 1; |
Eric W. Biederman | 5c1469d | 2010-06-13 03:28:03 +0000 | [diff] [blame] | 138 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 139 | /* Find the matching extent */ |
| 140 | extents = map->nr_extents; |
| 141 | smp_read_barrier_depends(); |
| 142 | for (idx = 0; idx < extents; idx++) { |
| 143 | first = map->extent[idx].first; |
| 144 | last = first + map->extent[idx].count - 1; |
| 145 | if (id >= first && id <= last && |
| 146 | (id2 >= first && id2 <= last)) |
| 147 | break; |
Eric W. Biederman | 5c1469d | 2010-06-13 03:28:03 +0000 | [diff] [blame] | 148 | } |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 149 | /* Map the id or note failure */ |
| 150 | if (idx < extents) |
| 151 | id = (id - first) + map->extent[idx].lower_first; |
| 152 | else |
| 153 | id = (u32) -1; |
Eric W. Biederman | 5c1469d | 2010-06-13 03:28:03 +0000 | [diff] [blame] | 154 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 155 | return id; |
Eric W. Biederman | 5c1469d | 2010-06-13 03:28:03 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 158 | static u32 map_id_down(struct uid_gid_map *map, u32 id) |
Eric W. Biederman | 5c1469d | 2010-06-13 03:28:03 +0000 | [diff] [blame] | 159 | { |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 160 | unsigned idx, extents; |
| 161 | u32 first, last; |
Eric W. Biederman | 5c1469d | 2010-06-13 03:28:03 +0000 | [diff] [blame] | 162 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 163 | /* Find the matching extent */ |
| 164 | extents = map->nr_extents; |
| 165 | smp_read_barrier_depends(); |
| 166 | for (idx = 0; idx < extents; idx++) { |
| 167 | first = map->extent[idx].first; |
| 168 | last = first + map->extent[idx].count - 1; |
| 169 | if (id >= first && id <= last) |
| 170 | break; |
| 171 | } |
| 172 | /* Map the id or note failure */ |
| 173 | if (idx < extents) |
| 174 | id = (id - first) + map->extent[idx].lower_first; |
| 175 | else |
| 176 | id = (u32) -1; |
Eric W. Biederman | 5c1469d | 2010-06-13 03:28:03 +0000 | [diff] [blame] | 177 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 178 | return id; |
| 179 | } |
| 180 | |
| 181 | static u32 map_id_up(struct uid_gid_map *map, u32 id) |
| 182 | { |
| 183 | unsigned idx, extents; |
| 184 | u32 first, last; |
| 185 | |
| 186 | /* Find the matching extent */ |
| 187 | extents = map->nr_extents; |
| 188 | smp_read_barrier_depends(); |
| 189 | for (idx = 0; idx < extents; idx++) { |
| 190 | first = map->extent[idx].lower_first; |
| 191 | last = first + map->extent[idx].count - 1; |
| 192 | if (id >= first && id <= last) |
| 193 | break; |
| 194 | } |
| 195 | /* Map the id or note failure */ |
| 196 | if (idx < extents) |
| 197 | id = (id - first) + map->extent[idx].first; |
| 198 | else |
| 199 | id = (u32) -1; |
| 200 | |
| 201 | return id; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * make_kuid - Map a user-namespace uid pair into a kuid. |
| 206 | * @ns: User namespace that the uid is in |
| 207 | * @uid: User identifier |
| 208 | * |
| 209 | * Maps a user-namespace uid pair into a kernel internal kuid, |
| 210 | * and returns that kuid. |
| 211 | * |
| 212 | * When there is no mapping defined for the user-namespace uid |
| 213 | * pair INVALID_UID is returned. Callers are expected to test |
| 214 | * for and handle handle INVALID_UID being returned. INVALID_UID |
| 215 | * may be tested for using uid_valid(). |
| 216 | */ |
| 217 | kuid_t make_kuid(struct user_namespace *ns, uid_t uid) |
| 218 | { |
| 219 | /* Map the uid to a global kernel uid */ |
| 220 | return KUIDT_INIT(map_id_down(&ns->uid_map, uid)); |
| 221 | } |
| 222 | EXPORT_SYMBOL(make_kuid); |
| 223 | |
| 224 | /** |
| 225 | * from_kuid - Create a uid from a kuid user-namespace pair. |
| 226 | * @targ: The user namespace we want a uid in. |
| 227 | * @kuid: The kernel internal uid to start with. |
| 228 | * |
| 229 | * Map @kuid into the user-namespace specified by @targ and |
| 230 | * return the resulting uid. |
| 231 | * |
| 232 | * There is always a mapping into the initial user_namespace. |
| 233 | * |
| 234 | * If @kuid has no mapping in @targ (uid_t)-1 is returned. |
| 235 | */ |
| 236 | uid_t from_kuid(struct user_namespace *targ, kuid_t kuid) |
| 237 | { |
| 238 | /* Map the uid from a global kernel uid */ |
| 239 | return map_id_up(&targ->uid_map, __kuid_val(kuid)); |
| 240 | } |
| 241 | EXPORT_SYMBOL(from_kuid); |
| 242 | |
| 243 | /** |
| 244 | * from_kuid_munged - Create a uid from a kuid user-namespace pair. |
| 245 | * @targ: The user namespace we want a uid in. |
| 246 | * @kuid: The kernel internal uid to start with. |
| 247 | * |
| 248 | * Map @kuid into the user-namespace specified by @targ and |
| 249 | * return the resulting uid. |
| 250 | * |
| 251 | * There is always a mapping into the initial user_namespace. |
| 252 | * |
| 253 | * Unlike from_kuid from_kuid_munged never fails and always |
| 254 | * returns a valid uid. This makes from_kuid_munged appropriate |
| 255 | * for use in syscalls like stat and getuid where failing the |
| 256 | * system call and failing to provide a valid uid are not an |
| 257 | * options. |
| 258 | * |
| 259 | * If @kuid has no mapping in @targ overflowuid is returned. |
| 260 | */ |
| 261 | uid_t from_kuid_munged(struct user_namespace *targ, kuid_t kuid) |
| 262 | { |
| 263 | uid_t uid; |
| 264 | uid = from_kuid(targ, kuid); |
| 265 | |
| 266 | if (uid == (uid_t) -1) |
| 267 | uid = overflowuid; |
| 268 | return uid; |
| 269 | } |
| 270 | EXPORT_SYMBOL(from_kuid_munged); |
| 271 | |
| 272 | /** |
| 273 | * make_kgid - Map a user-namespace gid pair into a kgid. |
| 274 | * @ns: User namespace that the gid is in |
| 275 | * @uid: group identifier |
| 276 | * |
| 277 | * Maps a user-namespace gid pair into a kernel internal kgid, |
| 278 | * and returns that kgid. |
| 279 | * |
| 280 | * When there is no mapping defined for the user-namespace gid |
| 281 | * pair INVALID_GID is returned. Callers are expected to test |
| 282 | * for and handle INVALID_GID being returned. INVALID_GID may be |
| 283 | * tested for using gid_valid(). |
| 284 | */ |
| 285 | kgid_t make_kgid(struct user_namespace *ns, gid_t gid) |
| 286 | { |
| 287 | /* Map the gid to a global kernel gid */ |
| 288 | return KGIDT_INIT(map_id_down(&ns->gid_map, gid)); |
| 289 | } |
| 290 | EXPORT_SYMBOL(make_kgid); |
| 291 | |
| 292 | /** |
| 293 | * from_kgid - Create a gid from a kgid user-namespace pair. |
| 294 | * @targ: The user namespace we want a gid in. |
| 295 | * @kgid: The kernel internal gid to start with. |
| 296 | * |
| 297 | * Map @kgid into the user-namespace specified by @targ and |
| 298 | * return the resulting gid. |
| 299 | * |
| 300 | * There is always a mapping into the initial user_namespace. |
| 301 | * |
| 302 | * If @kgid has no mapping in @targ (gid_t)-1 is returned. |
| 303 | */ |
| 304 | gid_t from_kgid(struct user_namespace *targ, kgid_t kgid) |
| 305 | { |
| 306 | /* Map the gid from a global kernel gid */ |
| 307 | return map_id_up(&targ->gid_map, __kgid_val(kgid)); |
| 308 | } |
| 309 | EXPORT_SYMBOL(from_kgid); |
| 310 | |
| 311 | /** |
| 312 | * from_kgid_munged - Create a gid from a kgid user-namespace pair. |
| 313 | * @targ: The user namespace we want a gid in. |
| 314 | * @kgid: The kernel internal gid to start with. |
| 315 | * |
| 316 | * Map @kgid into the user-namespace specified by @targ and |
| 317 | * return the resulting gid. |
| 318 | * |
| 319 | * There is always a mapping into the initial user_namespace. |
| 320 | * |
| 321 | * Unlike from_kgid from_kgid_munged never fails and always |
| 322 | * returns a valid gid. This makes from_kgid_munged appropriate |
| 323 | * for use in syscalls like stat and getgid where failing the |
| 324 | * system call and failing to provide a valid gid are not options. |
| 325 | * |
| 326 | * If @kgid has no mapping in @targ overflowgid is returned. |
| 327 | */ |
| 328 | gid_t from_kgid_munged(struct user_namespace *targ, kgid_t kgid) |
| 329 | { |
| 330 | gid_t gid; |
| 331 | gid = from_kgid(targ, kgid); |
| 332 | |
| 333 | if (gid == (gid_t) -1) |
| 334 | gid = overflowgid; |
| 335 | return gid; |
| 336 | } |
| 337 | EXPORT_SYMBOL(from_kgid_munged); |
| 338 | |
Eric W. Biederman | f76d207 | 2012-08-30 01:24:05 -0700 | [diff] [blame] | 339 | /** |
| 340 | * make_kprojid - Map a user-namespace projid pair into a kprojid. |
| 341 | * @ns: User namespace that the projid is in |
| 342 | * @projid: Project identifier |
| 343 | * |
| 344 | * Maps a user-namespace uid pair into a kernel internal kuid, |
| 345 | * and returns that kuid. |
| 346 | * |
| 347 | * When there is no mapping defined for the user-namespace projid |
| 348 | * pair INVALID_PROJID is returned. Callers are expected to test |
| 349 | * for and handle handle INVALID_PROJID being returned. INVALID_PROJID |
| 350 | * may be tested for using projid_valid(). |
| 351 | */ |
| 352 | kprojid_t make_kprojid(struct user_namespace *ns, projid_t projid) |
| 353 | { |
| 354 | /* Map the uid to a global kernel uid */ |
| 355 | return KPROJIDT_INIT(map_id_down(&ns->projid_map, projid)); |
| 356 | } |
| 357 | EXPORT_SYMBOL(make_kprojid); |
| 358 | |
| 359 | /** |
| 360 | * from_kprojid - Create a projid from a kprojid user-namespace pair. |
| 361 | * @targ: The user namespace we want a projid in. |
| 362 | * @kprojid: The kernel internal project identifier to start with. |
| 363 | * |
| 364 | * Map @kprojid into the user-namespace specified by @targ and |
| 365 | * return the resulting projid. |
| 366 | * |
| 367 | * There is always a mapping into the initial user_namespace. |
| 368 | * |
| 369 | * If @kprojid has no mapping in @targ (projid_t)-1 is returned. |
| 370 | */ |
| 371 | projid_t from_kprojid(struct user_namespace *targ, kprojid_t kprojid) |
| 372 | { |
| 373 | /* Map the uid from a global kernel uid */ |
| 374 | return map_id_up(&targ->projid_map, __kprojid_val(kprojid)); |
| 375 | } |
| 376 | EXPORT_SYMBOL(from_kprojid); |
| 377 | |
| 378 | /** |
| 379 | * from_kprojid_munged - Create a projiid from a kprojid user-namespace pair. |
| 380 | * @targ: The user namespace we want a projid in. |
| 381 | * @kprojid: The kernel internal projid to start with. |
| 382 | * |
| 383 | * Map @kprojid into the user-namespace specified by @targ and |
| 384 | * return the resulting projid. |
| 385 | * |
| 386 | * There is always a mapping into the initial user_namespace. |
| 387 | * |
| 388 | * Unlike from_kprojid from_kprojid_munged never fails and always |
| 389 | * returns a valid projid. This makes from_kprojid_munged |
| 390 | * appropriate for use in syscalls like stat and where |
| 391 | * failing the system call and failing to provide a valid projid are |
| 392 | * not an options. |
| 393 | * |
| 394 | * If @kprojid has no mapping in @targ OVERFLOW_PROJID is returned. |
| 395 | */ |
| 396 | projid_t from_kprojid_munged(struct user_namespace *targ, kprojid_t kprojid) |
| 397 | { |
| 398 | projid_t projid; |
| 399 | projid = from_kprojid(targ, kprojid); |
| 400 | |
| 401 | if (projid == (projid_t) -1) |
| 402 | projid = OVERFLOW_PROJID; |
| 403 | return projid; |
| 404 | } |
| 405 | EXPORT_SYMBOL(from_kprojid_munged); |
| 406 | |
| 407 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 408 | static int uid_m_show(struct seq_file *seq, void *v) |
| 409 | { |
| 410 | struct user_namespace *ns = seq->private; |
| 411 | struct uid_gid_extent *extent = v; |
| 412 | struct user_namespace *lower_ns; |
| 413 | uid_t lower; |
| 414 | |
Eric W. Biederman | c450f37 | 2012-08-14 21:25:13 -0700 | [diff] [blame] | 415 | lower_ns = seq_user_ns(seq); |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 416 | if ((lower_ns == ns) && lower_ns->parent) |
| 417 | lower_ns = lower_ns->parent; |
| 418 | |
| 419 | lower = from_kuid(lower_ns, KUIDT_INIT(extent->lower_first)); |
| 420 | |
| 421 | seq_printf(seq, "%10u %10u %10u\n", |
| 422 | extent->first, |
| 423 | lower, |
| 424 | extent->count); |
| 425 | |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | static int gid_m_show(struct seq_file *seq, void *v) |
| 430 | { |
| 431 | struct user_namespace *ns = seq->private; |
| 432 | struct uid_gid_extent *extent = v; |
| 433 | struct user_namespace *lower_ns; |
| 434 | gid_t lower; |
| 435 | |
Eric W. Biederman | c450f37 | 2012-08-14 21:25:13 -0700 | [diff] [blame] | 436 | lower_ns = seq_user_ns(seq); |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 437 | if ((lower_ns == ns) && lower_ns->parent) |
| 438 | lower_ns = lower_ns->parent; |
| 439 | |
| 440 | lower = from_kgid(lower_ns, KGIDT_INIT(extent->lower_first)); |
| 441 | |
| 442 | seq_printf(seq, "%10u %10u %10u\n", |
| 443 | extent->first, |
| 444 | lower, |
| 445 | extent->count); |
| 446 | |
| 447 | return 0; |
| 448 | } |
| 449 | |
Eric W. Biederman | f76d207 | 2012-08-30 01:24:05 -0700 | [diff] [blame] | 450 | static int projid_m_show(struct seq_file *seq, void *v) |
| 451 | { |
| 452 | struct user_namespace *ns = seq->private; |
| 453 | struct uid_gid_extent *extent = v; |
| 454 | struct user_namespace *lower_ns; |
| 455 | projid_t lower; |
| 456 | |
| 457 | lower_ns = seq_user_ns(seq); |
| 458 | if ((lower_ns == ns) && lower_ns->parent) |
| 459 | lower_ns = lower_ns->parent; |
| 460 | |
| 461 | lower = from_kprojid(lower_ns, KPROJIDT_INIT(extent->lower_first)); |
| 462 | |
| 463 | seq_printf(seq, "%10u %10u %10u\n", |
| 464 | extent->first, |
| 465 | lower, |
| 466 | extent->count); |
| 467 | |
| 468 | return 0; |
| 469 | } |
| 470 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 471 | static void *m_start(struct seq_file *seq, loff_t *ppos, struct uid_gid_map *map) |
| 472 | { |
| 473 | struct uid_gid_extent *extent = NULL; |
| 474 | loff_t pos = *ppos; |
| 475 | |
| 476 | if (pos < map->nr_extents) |
| 477 | extent = &map->extent[pos]; |
| 478 | |
| 479 | return extent; |
| 480 | } |
| 481 | |
| 482 | static void *uid_m_start(struct seq_file *seq, loff_t *ppos) |
| 483 | { |
| 484 | struct user_namespace *ns = seq->private; |
| 485 | |
| 486 | return m_start(seq, ppos, &ns->uid_map); |
| 487 | } |
| 488 | |
| 489 | static void *gid_m_start(struct seq_file *seq, loff_t *ppos) |
| 490 | { |
| 491 | struct user_namespace *ns = seq->private; |
| 492 | |
| 493 | return m_start(seq, ppos, &ns->gid_map); |
| 494 | } |
| 495 | |
Eric W. Biederman | f76d207 | 2012-08-30 01:24:05 -0700 | [diff] [blame] | 496 | static void *projid_m_start(struct seq_file *seq, loff_t *ppos) |
| 497 | { |
| 498 | struct user_namespace *ns = seq->private; |
| 499 | |
| 500 | return m_start(seq, ppos, &ns->projid_map); |
| 501 | } |
| 502 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 503 | static void *m_next(struct seq_file *seq, void *v, loff_t *pos) |
| 504 | { |
| 505 | (*pos)++; |
| 506 | return seq->op->start(seq, pos); |
| 507 | } |
| 508 | |
| 509 | static void m_stop(struct seq_file *seq, void *v) |
| 510 | { |
| 511 | return; |
| 512 | } |
| 513 | |
| 514 | struct seq_operations proc_uid_seq_operations = { |
| 515 | .start = uid_m_start, |
| 516 | .stop = m_stop, |
| 517 | .next = m_next, |
| 518 | .show = uid_m_show, |
| 519 | }; |
| 520 | |
| 521 | struct seq_operations proc_gid_seq_operations = { |
| 522 | .start = gid_m_start, |
| 523 | .stop = m_stop, |
| 524 | .next = m_next, |
| 525 | .show = gid_m_show, |
| 526 | }; |
| 527 | |
Eric W. Biederman | f76d207 | 2012-08-30 01:24:05 -0700 | [diff] [blame] | 528 | struct seq_operations proc_projid_seq_operations = { |
| 529 | .start = projid_m_start, |
| 530 | .stop = m_stop, |
| 531 | .next = m_next, |
| 532 | .show = projid_m_show, |
| 533 | }; |
| 534 | |
Eric W. Biederman | 0bd14b4 | 2012-12-27 22:27:29 -0800 | [diff] [blame] | 535 | static bool mappings_overlap(struct uid_gid_map *new_map, struct uid_gid_extent *extent) |
| 536 | { |
| 537 | u32 upper_first, lower_first, upper_last, lower_last; |
| 538 | unsigned idx; |
| 539 | |
| 540 | upper_first = extent->first; |
| 541 | lower_first = extent->lower_first; |
| 542 | upper_last = upper_first + extent->count - 1; |
| 543 | lower_last = lower_first + extent->count - 1; |
| 544 | |
| 545 | for (idx = 0; idx < new_map->nr_extents; idx++) { |
| 546 | u32 prev_upper_first, prev_lower_first; |
| 547 | u32 prev_upper_last, prev_lower_last; |
| 548 | struct uid_gid_extent *prev; |
| 549 | |
| 550 | prev = &new_map->extent[idx]; |
| 551 | |
| 552 | prev_upper_first = prev->first; |
| 553 | prev_lower_first = prev->lower_first; |
| 554 | prev_upper_last = prev_upper_first + prev->count - 1; |
| 555 | prev_lower_last = prev_lower_first + prev->count - 1; |
| 556 | |
| 557 | /* Does the upper range intersect a previous extent? */ |
| 558 | if ((prev_upper_first <= upper_last) && |
| 559 | (prev_upper_last >= upper_first)) |
| 560 | return true; |
| 561 | |
| 562 | /* Does the lower range intersect a previous extent? */ |
| 563 | if ((prev_lower_first <= lower_last) && |
| 564 | (prev_lower_last >= lower_first)) |
| 565 | return true; |
| 566 | } |
| 567 | return false; |
| 568 | } |
| 569 | |
| 570 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 571 | static DEFINE_MUTEX(id_map_mutex); |
| 572 | |
| 573 | static ssize_t map_write(struct file *file, const char __user *buf, |
| 574 | size_t count, loff_t *ppos, |
| 575 | int cap_setid, |
| 576 | struct uid_gid_map *map, |
| 577 | struct uid_gid_map *parent_map) |
| 578 | { |
| 579 | struct seq_file *seq = file->private_data; |
| 580 | struct user_namespace *ns = seq->private; |
| 581 | struct uid_gid_map new_map; |
| 582 | unsigned idx; |
Eric W. Biederman | 0bd14b4 | 2012-12-27 22:27:29 -0800 | [diff] [blame] | 583 | struct uid_gid_extent *extent = NULL; |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 584 | unsigned long page = 0; |
| 585 | char *kbuf, *pos, *next_line; |
| 586 | ssize_t ret = -EINVAL; |
| 587 | |
| 588 | /* |
| 589 | * The id_map_mutex serializes all writes to any given map. |
| 590 | * |
| 591 | * Any map is only ever written once. |
| 592 | * |
| 593 | * An id map fits within 1 cache line on most architectures. |
| 594 | * |
| 595 | * On read nothing needs to be done unless you are on an |
| 596 | * architecture with a crazy cache coherency model like alpha. |
| 597 | * |
| 598 | * There is a one time data dependency between reading the |
| 599 | * count of the extents and the values of the extents. The |
| 600 | * desired behavior is to see the values of the extents that |
| 601 | * were written before the count of the extents. |
| 602 | * |
| 603 | * To achieve this smp_wmb() is used on guarantee the write |
| 604 | * order and smp_read_barrier_depends() is guaranteed that we |
| 605 | * don't have crazy architectures returning stale data. |
| 606 | * |
Eric W. Biederman | 5c1469d | 2010-06-13 03:28:03 +0000 | [diff] [blame] | 607 | */ |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 608 | mutex_lock(&id_map_mutex); |
| 609 | |
| 610 | ret = -EPERM; |
| 611 | /* Only allow one successful write to the map */ |
| 612 | if (map->nr_extents != 0) |
| 613 | goto out; |
| 614 | |
| 615 | /* Require the appropriate privilege CAP_SETUID or CAP_SETGID |
| 616 | * over the user namespace in order to set the id mapping. |
| 617 | */ |
Eric W. Biederman | f76d207 | 2012-08-30 01:24:05 -0700 | [diff] [blame] | 618 | if (cap_valid(cap_setid) && !ns_capable(ns, cap_setid)) |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 619 | goto out; |
| 620 | |
| 621 | /* Get a buffer */ |
| 622 | ret = -ENOMEM; |
| 623 | page = __get_free_page(GFP_TEMPORARY); |
| 624 | kbuf = (char *) page; |
| 625 | if (!page) |
| 626 | goto out; |
| 627 | |
| 628 | /* Only allow <= page size writes at the beginning of the file */ |
| 629 | ret = -EINVAL; |
| 630 | if ((*ppos != 0) || (count >= PAGE_SIZE)) |
| 631 | goto out; |
| 632 | |
| 633 | /* Slurp in the user data */ |
| 634 | ret = -EFAULT; |
| 635 | if (copy_from_user(kbuf, buf, count)) |
| 636 | goto out; |
| 637 | kbuf[count] = '\0'; |
| 638 | |
| 639 | /* Parse the user data */ |
| 640 | ret = -EINVAL; |
| 641 | pos = kbuf; |
| 642 | new_map.nr_extents = 0; |
| 643 | for (;pos; pos = next_line) { |
| 644 | extent = &new_map.extent[new_map.nr_extents]; |
| 645 | |
| 646 | /* Find the end of line and ensure I don't look past it */ |
| 647 | next_line = strchr(pos, '\n'); |
| 648 | if (next_line) { |
| 649 | *next_line = '\0'; |
| 650 | next_line++; |
| 651 | if (*next_line == '\0') |
| 652 | next_line = NULL; |
Eric W. Biederman | 5c1469d | 2010-06-13 03:28:03 +0000 | [diff] [blame] | 653 | } |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 654 | |
| 655 | pos = skip_spaces(pos); |
| 656 | extent->first = simple_strtoul(pos, &pos, 10); |
| 657 | if (!isspace(*pos)) |
| 658 | goto out; |
| 659 | |
| 660 | pos = skip_spaces(pos); |
| 661 | extent->lower_first = simple_strtoul(pos, &pos, 10); |
| 662 | if (!isspace(*pos)) |
| 663 | goto out; |
| 664 | |
| 665 | pos = skip_spaces(pos); |
| 666 | extent->count = simple_strtoul(pos, &pos, 10); |
| 667 | if (*pos && !isspace(*pos)) |
| 668 | goto out; |
| 669 | |
| 670 | /* Verify there is not trailing junk on the line */ |
| 671 | pos = skip_spaces(pos); |
| 672 | if (*pos != '\0') |
| 673 | goto out; |
| 674 | |
| 675 | /* Verify we have been given valid starting values */ |
| 676 | if ((extent->first == (u32) -1) || |
| 677 | (extent->lower_first == (u32) -1 )) |
| 678 | goto out; |
| 679 | |
| 680 | /* Verify count is not zero and does not cause the extent to wrap */ |
| 681 | if ((extent->first + extent->count) <= extent->first) |
| 682 | goto out; |
| 683 | if ((extent->lower_first + extent->count) <= extent->lower_first) |
| 684 | goto out; |
| 685 | |
Eric W. Biederman | 0bd14b4 | 2012-12-27 22:27:29 -0800 | [diff] [blame] | 686 | /* Do the ranges in extent overlap any previous extents? */ |
| 687 | if (mappings_overlap(&new_map, extent)) |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 688 | goto out; |
| 689 | |
| 690 | new_map.nr_extents++; |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 691 | |
| 692 | /* Fail if the file contains too many extents */ |
| 693 | if ((new_map.nr_extents == UID_GID_MAP_MAX_EXTENTS) && |
| 694 | (next_line != NULL)) |
| 695 | goto out; |
| 696 | } |
| 697 | /* Be very certaint the new map actually exists */ |
| 698 | if (new_map.nr_extents == 0) |
| 699 | goto out; |
| 700 | |
| 701 | ret = -EPERM; |
| 702 | /* Validate the user is allowed to use user id's mapped to. */ |
| 703 | if (!new_idmap_permitted(ns, cap_setid, &new_map)) |
| 704 | goto out; |
| 705 | |
| 706 | /* Map the lower ids from the parent user namespace to the |
| 707 | * kernel global id space. |
| 708 | */ |
| 709 | for (idx = 0; idx < new_map.nr_extents; idx++) { |
| 710 | u32 lower_first; |
| 711 | extent = &new_map.extent[idx]; |
| 712 | |
| 713 | lower_first = map_id_range_down(parent_map, |
| 714 | extent->lower_first, |
| 715 | extent->count); |
| 716 | |
| 717 | /* Fail if we can not map the specified extent to |
| 718 | * the kernel global id space. |
| 719 | */ |
| 720 | if (lower_first == (u32) -1) |
| 721 | goto out; |
| 722 | |
| 723 | extent->lower_first = lower_first; |
Eric W. Biederman | 5c1469d | 2010-06-13 03:28:03 +0000 | [diff] [blame] | 724 | } |
| 725 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 726 | /* Install the map */ |
| 727 | memcpy(map->extent, new_map.extent, |
| 728 | new_map.nr_extents*sizeof(new_map.extent[0])); |
| 729 | smp_wmb(); |
| 730 | map->nr_extents = new_map.nr_extents; |
| 731 | |
| 732 | *ppos = count; |
| 733 | ret = count; |
| 734 | out: |
| 735 | mutex_unlock(&id_map_mutex); |
| 736 | if (page) |
| 737 | free_page(page); |
| 738 | return ret; |
| 739 | } |
| 740 | |
| 741 | ssize_t proc_uid_map_write(struct file *file, const char __user *buf, size_t size, loff_t *ppos) |
| 742 | { |
| 743 | struct seq_file *seq = file->private_data; |
| 744 | struct user_namespace *ns = seq->private; |
Eric W. Biederman | c450f37 | 2012-08-14 21:25:13 -0700 | [diff] [blame] | 745 | struct user_namespace *seq_ns = seq_user_ns(seq); |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 746 | |
| 747 | if (!ns->parent) |
| 748 | return -EPERM; |
| 749 | |
Eric W. Biederman | c450f37 | 2012-08-14 21:25:13 -0700 | [diff] [blame] | 750 | if ((seq_ns != ns) && (seq_ns != ns->parent)) |
| 751 | return -EPERM; |
| 752 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 753 | return map_write(file, buf, size, ppos, CAP_SETUID, |
| 754 | &ns->uid_map, &ns->parent->uid_map); |
| 755 | } |
| 756 | |
| 757 | ssize_t proc_gid_map_write(struct file *file, const char __user *buf, size_t size, loff_t *ppos) |
| 758 | { |
| 759 | struct seq_file *seq = file->private_data; |
| 760 | struct user_namespace *ns = seq->private; |
Eric W. Biederman | c450f37 | 2012-08-14 21:25:13 -0700 | [diff] [blame] | 761 | struct user_namespace *seq_ns = seq_user_ns(seq); |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 762 | |
| 763 | if (!ns->parent) |
| 764 | return -EPERM; |
| 765 | |
Eric W. Biederman | c450f37 | 2012-08-14 21:25:13 -0700 | [diff] [blame] | 766 | if ((seq_ns != ns) && (seq_ns != ns->parent)) |
| 767 | return -EPERM; |
| 768 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 769 | return map_write(file, buf, size, ppos, CAP_SETGID, |
| 770 | &ns->gid_map, &ns->parent->gid_map); |
| 771 | } |
| 772 | |
Eric W. Biederman | f76d207 | 2012-08-30 01:24:05 -0700 | [diff] [blame] | 773 | ssize_t proc_projid_map_write(struct file *file, const char __user *buf, size_t size, loff_t *ppos) |
| 774 | { |
| 775 | struct seq_file *seq = file->private_data; |
| 776 | struct user_namespace *ns = seq->private; |
| 777 | struct user_namespace *seq_ns = seq_user_ns(seq); |
| 778 | |
| 779 | if (!ns->parent) |
| 780 | return -EPERM; |
| 781 | |
| 782 | if ((seq_ns != ns) && (seq_ns != ns->parent)) |
| 783 | return -EPERM; |
| 784 | |
| 785 | /* Anyone can set any valid project id no capability needed */ |
| 786 | return map_write(file, buf, size, ppos, -1, |
| 787 | &ns->projid_map, &ns->parent->projid_map); |
| 788 | } |
| 789 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 790 | static bool new_idmap_permitted(struct user_namespace *ns, int cap_setid, |
| 791 | struct uid_gid_map *new_map) |
| 792 | { |
Eric W. Biederman | 37657da | 2012-07-27 06:21:27 -0700 | [diff] [blame] | 793 | /* Allow mapping to your own filesystem ids */ |
| 794 | if ((new_map->nr_extents == 1) && (new_map->extent[0].count == 1)) { |
| 795 | u32 id = new_map->extent[0].lower_first; |
| 796 | if (cap_setid == CAP_SETUID) { |
| 797 | kuid_t uid = make_kuid(ns->parent, id); |
| 798 | if (uid_eq(uid, current_fsuid())) |
| 799 | return true; |
| 800 | } |
| 801 | else if (cap_setid == CAP_SETGID) { |
| 802 | kgid_t gid = make_kgid(ns->parent, id); |
| 803 | if (gid_eq(gid, current_fsgid())) |
| 804 | return true; |
| 805 | } |
| 806 | } |
| 807 | |
Eric W. Biederman | f76d207 | 2012-08-30 01:24:05 -0700 | [diff] [blame] | 808 | /* Allow anyone to set a mapping that doesn't require privilege */ |
| 809 | if (!cap_valid(cap_setid)) |
| 810 | return true; |
| 811 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 812 | /* Allow the specified ids if we have the appropriate capability |
| 813 | * (CAP_SETUID or CAP_SETGID) over the parent user namespace. |
| 814 | */ |
| 815 | if (ns_capable(ns->parent, cap_setid)) |
| 816 | return true; |
| 817 | |
| 818 | return false; |
Eric W. Biederman | 5c1469d | 2010-06-13 03:28:03 +0000 | [diff] [blame] | 819 | } |
Pavel Emelyanov | 6164281 | 2011-01-12 17:00:46 -0800 | [diff] [blame] | 820 | |
Eric W. Biederman | cde1975 | 2012-07-26 06:24:06 -0700 | [diff] [blame] | 821 | static void *userns_get(struct task_struct *task) |
| 822 | { |
| 823 | struct user_namespace *user_ns; |
| 824 | |
| 825 | rcu_read_lock(); |
| 826 | user_ns = get_user_ns(__task_cred(task)->user_ns); |
| 827 | rcu_read_unlock(); |
| 828 | |
| 829 | return user_ns; |
| 830 | } |
| 831 | |
| 832 | static void userns_put(void *ns) |
| 833 | { |
| 834 | put_user_ns(ns); |
| 835 | } |
| 836 | |
| 837 | static int userns_install(struct nsproxy *nsproxy, void *ns) |
| 838 | { |
| 839 | struct user_namespace *user_ns = ns; |
| 840 | struct cred *cred; |
| 841 | |
| 842 | /* Don't allow gaining capabilities by reentering |
| 843 | * the same user namespace. |
| 844 | */ |
| 845 | if (user_ns == current_user_ns()) |
| 846 | return -EINVAL; |
| 847 | |
Eric W. Biederman | 5155040 | 2012-12-09 17:19:52 -0800 | [diff] [blame] | 848 | /* Threaded processes may not enter a different user namespace */ |
Eric W. Biederman | cde1975 | 2012-07-26 06:24:06 -0700 | [diff] [blame] | 849 | if (atomic_read(¤t->mm->mm_users) > 1) |
| 850 | return -EINVAL; |
| 851 | |
Eric W. Biederman | e66eded | 2013-03-13 11:51:49 -0700 | [diff] [blame] | 852 | if (current->fs->users != 1) |
| 853 | return -EINVAL; |
| 854 | |
Eric W. Biederman | cde1975 | 2012-07-26 06:24:06 -0700 | [diff] [blame] | 855 | if (!ns_capable(user_ns, CAP_SYS_ADMIN)) |
| 856 | return -EPERM; |
| 857 | |
| 858 | cred = prepare_creds(); |
| 859 | if (!cred) |
| 860 | return -ENOMEM; |
| 861 | |
| 862 | put_user_ns(cred->user_ns); |
| 863 | set_cred_user_ns(cred, get_user_ns(user_ns)); |
| 864 | |
| 865 | return commit_creds(cred); |
| 866 | } |
| 867 | |
Eric W. Biederman | 98f842e | 2011-06-15 10:21:48 -0700 | [diff] [blame] | 868 | static unsigned int userns_inum(void *ns) |
| 869 | { |
| 870 | struct user_namespace *user_ns = ns; |
| 871 | return user_ns->proc_inum; |
| 872 | } |
| 873 | |
Eric W. Biederman | cde1975 | 2012-07-26 06:24:06 -0700 | [diff] [blame] | 874 | const struct proc_ns_operations userns_operations = { |
| 875 | .name = "user", |
| 876 | .type = CLONE_NEWUSER, |
| 877 | .get = userns_get, |
| 878 | .put = userns_put, |
| 879 | .install = userns_install, |
Eric W. Biederman | 98f842e | 2011-06-15 10:21:48 -0700 | [diff] [blame] | 880 | .inum = userns_inum, |
Eric W. Biederman | cde1975 | 2012-07-26 06:24:06 -0700 | [diff] [blame] | 881 | }; |
| 882 | |
Pavel Emelyanov | 6164281 | 2011-01-12 17:00:46 -0800 | [diff] [blame] | 883 | static __init int user_namespaces_init(void) |
| 884 | { |
| 885 | user_ns_cachep = KMEM_CACHE(user_namespace, SLAB_PANIC); |
| 886 | return 0; |
| 887 | } |
| 888 | module_init(user_namespaces_init); |