8 #include <linux/export.h>
10 #include <linux/slab.h>
14 #include <linux/securebits.h>
21 #include <linux/ctype.h>
47 if (!kuid_has_mapping(parent_ns, owner) ||
48 !kgid_has_mapping(parent_ns, group))
51 ns = kmem_cache_zalloc(user_ns_cachep,
GFP_KERNEL);
64 new->cap_inheritable = CAP_EMPTY_SET;
65 new->cap_permitted = CAP_FULL_SET;
66 new->cap_effective = CAP_FULL_SET;
67 new->cap_bset = CAP_FULL_SET;
70 new->request_key_auth =
NULL;
94 unsigned idx, extents;
102 for (idx = 0; idx < extents; idx++) {
104 last = first + map->
extent[
idx].count - 1;
105 if (
id >= first &&
id <= last &&
106 (id2 >= first && id2 <= last))
120 unsigned idx, extents;
126 for (idx = 0; idx < extents; idx++) {
128 last = first + map->
extent[
idx].count - 1;
129 if (
id >= first &&
id <= last)
143 unsigned idx, extents;
149 for (idx = 0; idx < extents; idx++) {
151 last = first + map->
extent[
idx].count - 1;
152 if (
id >= first &&
id <= last)
199 return map_id_up(&targ->
uid_map, __kuid_val(kuid));
226 if (uid == (
uid_t) -1)
267 return map_id_up(&targ->
gid_map, __kgid_val(kgid));
293 if (gid == (
gid_t) -1)
334 return map_id_up(&targ->
projid_map, __kprojid_val(kprojid));
368 static int uid_m_show(
struct seq_file *seq,
void *
v)
371 struct uid_gid_extent *
extent =
v;
376 if ((lower_ns == ns) && lower_ns->
parent)
377 lower_ns = lower_ns->
parent;
389 static int gid_m_show(
struct seq_file *seq,
void *v)
392 struct uid_gid_extent *extent =
v;
397 if ((lower_ns == ns) && lower_ns->
parent)
398 lower_ns = lower_ns->
parent;
410 static int projid_m_show(
struct seq_file *seq,
void *v)
413 struct uid_gid_extent *extent =
v;
417 lower_ns = seq_user_ns(seq);
418 if ((lower_ns == ns) && lower_ns->
parent)
419 lower_ns = lower_ns->
parent;
433 struct uid_gid_extent *extent =
NULL;
436 if (pos < map->nr_extents)
442 static void *uid_m_start(
struct seq_file *seq, loff_t *ppos)
446 return m_start(seq, ppos, &ns->
uid_map);
449 static void *gid_m_start(
struct seq_file *seq, loff_t *ppos)
453 return m_start(seq, ppos, &ns->
gid_map);
456 static void *projid_m_start(
struct seq_file *seq, loff_t *ppos)
463 static void *m_next(
struct seq_file *seq,
void *v, loff_t *pos)
466 return seq->
op->start(seq, pos);
469 static void m_stop(
struct seq_file *seq,
void *v)
475 .start = uid_m_start,
482 .start = gid_m_start,
489 .start = projid_m_start,
492 .show = projid_m_show,
498 size_t count, loff_t *ppos,
508 unsigned long page = 0;
509 char *kbuf, *
pos, *next_line;
548 kbuf = (
char *) page;
554 if ((*ppos != 0) || (count >=
PAGE_SIZE))
566 new_map.nr_extents = 0;
567 for (;
pos; pos = next_line) {
568 extent = &new_map.extent[new_map.nr_extents];
571 next_line =
strchr(pos,
'\n');
575 if (*next_line ==
'\0')
600 if ((extent->first == (
u32) -1) ||
601 (extent->lower_first == (
u32) -1 ))
605 if ((extent->first + extent->count) <= extent->first)
607 if ((extent->lower_first + extent->count) <= extent->lower_first)
612 (((last->first + last->count) > extent->first) ||
613 ((last->lower_first + last->count) > extent->lower_first)))
616 new_map.nr_extents++;
625 if (new_map.nr_extents == 0)
630 if (!new_idmap_permitted(ns, cap_setid, &new_map))
636 for (idx = 0; idx < new_map.nr_extents; idx++) {
638 extent = &new_map.extent[
idx];
640 lower_first = map_id_range_down(parent_map,
647 if (lower_first == (
u32) -1)
650 extent->lower_first = lower_first;
655 new_map.nr_extents*
sizeof(new_map.extent[0]));
701 if ((seq_ns != ns) && (seq_ns != ns->
parent))
705 return map_write(file, buf, size, ppos, -1,
709 static bool new_idmap_permitted(
struct user_namespace *ns,
int cap_setid,
725 static __init int user_namespaces_init(
void)