Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 357755
b: refs/heads/master
c: 0bd14b4
h: refs/heads/master
i:
  357753: 25185fa
  357751: d562619
v: v3
  • Loading branch information
Eric W. Biederman committed Jan 27, 2013
1 parent 0c438f1 commit 651056f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: c61a2810a2161986353705b44d9503e6bb079f4f
refs/heads/master: 0bd14b4fd72afd5df41e9fd59f356740f22fceba
45 changes: 39 additions & 6 deletions trunk/kernel/user_namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,42 @@ struct seq_operations proc_projid_seq_operations = {
.show = projid_m_show,
};

static bool mappings_overlap(struct uid_gid_map *new_map, struct uid_gid_extent *extent)
{
u32 upper_first, lower_first, upper_last, lower_last;
unsigned idx;

upper_first = extent->first;
lower_first = extent->lower_first;
upper_last = upper_first + extent->count - 1;
lower_last = lower_first + extent->count - 1;

for (idx = 0; idx < new_map->nr_extents; idx++) {
u32 prev_upper_first, prev_lower_first;
u32 prev_upper_last, prev_lower_last;
struct uid_gid_extent *prev;

prev = &new_map->extent[idx];

prev_upper_first = prev->first;
prev_lower_first = prev->lower_first;
prev_upper_last = prev_upper_first + prev->count - 1;
prev_lower_last = prev_lower_first + prev->count - 1;

/* Does the upper range intersect a previous extent? */
if ((prev_upper_first <= upper_last) &&
(prev_upper_last >= upper_first))
return true;

/* Does the lower range intersect a previous extent? */
if ((prev_lower_first <= lower_last) &&
(prev_lower_last >= lower_first))
return true;
}
return false;
}


static DEFINE_MUTEX(id_map_mutex);

static ssize_t map_write(struct file *file, const char __user *buf,
Expand All @@ -532,7 +568,7 @@ static ssize_t map_write(struct file *file, const char __user *buf,
struct user_namespace *ns = seq->private;
struct uid_gid_map new_map;
unsigned idx;
struct uid_gid_extent *extent, *last = NULL;
struct uid_gid_extent *extent = NULL;
unsigned long page = 0;
char *kbuf, *pos, *next_line;
ssize_t ret = -EINVAL;
Expand Down Expand Up @@ -635,14 +671,11 @@ static ssize_t map_write(struct file *file, const char __user *buf,
if ((extent->lower_first + extent->count) <= extent->lower_first)
goto out;

/* For now only accept extents that are strictly in order */
if (last &&
(((last->first + last->count) > extent->first) ||
((last->lower_first + last->count) > extent->lower_first)))
/* Do the ranges in extent overlap any previous extents? */
if (mappings_overlap(&new_map, extent))
goto out;

new_map.nr_extents++;
last = extent;

/* Fail if the file contains too many extents */
if ((new_map.nr_extents == UID_GID_MAP_MAX_EXTENTS) &&
Expand Down

0 comments on commit 651056f

Please sign in to comment.