userns: add argument sanity checking

In find_new_sub_{u,g}ids, check for min, count and max values.

In idmapping.c:get_map_ranges(), make sure that the value passed
in for ranges did not overflow.  Couldn't happen with the current
code, but this is a sanity check for any future potential mis-uses.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
Serge Hallyn
2013-06-21 11:47:36 -05:00
parent 673c2a6f9a
commit c0ce911b5e
3 changed files with 26 additions and 0 deletions

View File

@ -58,6 +58,14 @@ int find_new_sub_uids (const char *owner,
max = getdef_ulong ("SUB_UID_MAX", 600100000UL);
count = getdef_ulong ("SUB_UID_COUNT", 10000);
if (min >= max || count >= max || (min + count) >= max) {
(void) fprintf (stderr,
_("%s: Invalid configuration: SUB_UID_MIN (%lu),"
" SUB_UID_MAX (%lu), SUB_UID_COUNT (%lu)\n"),
Prog, min, max, count);
return -1;
}
/* Is there a preferred range that works? */
if ((*range_count != 0) &&
(*range_start >= min) &&