Skip to content

Commit 403ea61

Browse files
committed
zdtm: support ext-uid-map flag for full UID/GID range in user namespaces
Tests that use supplementary group IDs beyond the default mapping range (e.g. GIDs in the billion scale) fail with EINVAL in user namespace mode because the GIDs are not mapped. Add support for the 'ext-uid-map' test flag: when set, ZDTM_UID_MAP and ZDTM_GID_MAP are populated with a full 32-bit identity mapping (0 0 4294967295), allowing the child user namespace to access the full UID/GID space. Signed-off-by: dong sunchao <dongsunchao@gmail.com>
1 parent bfb8599 commit 403ea61

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

test/zdtm.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,10 @@ def start(self):
511511
else:
512512
print("Test is SUID")
513513

514+
if test_flag(self.__desc, 'ext-uid-map'):
515+
env['ZDTM_UID_MAP'] = "0 0 4294967295"
516+
env['ZDTM_GID_MAP'] = "0 0 4294967295"
517+
514518
if self.__flavor.ns:
515519
env['ZDTM_NEWNS'] = "1"
516520
env['ZDTM_ROOT'] = self.__flavor.root

test/zdtm/lib/ns.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,15 +492,20 @@ void ns_create(int argc, char **argv)
492492
char pname[PATH_MAX];
493493
int fd;
494494

495+
char *ext_uid_map = getenv("ZDTM_UID_MAP");
496+
char *ext_gid_map = getenv("ZDTM_GID_MAP");
497+
495498
snprintf(pname, sizeof(pname), "/proc/%d/uid_map", pid);
496499
fd = open(pname, O_WRONLY);
497500
if (fd < 0) {
498501
fprintf(stderr, "open(%s): %m\n", pname);
499502
exit(1);
500503
}
501-
if (write(fd, UID_MAP, sizeof(UID_MAP)) < 0) {
502-
fprintf(stderr, "write(" UID_MAP "): %m\n");
503-
exit(1);
504+
505+
if (ext_uid_map) {
506+
dprintf(fd, "%s", ext_uid_map);
507+
} else {
508+
write(fd, UID_MAP, sizeof(UID_MAP) - 1);
504509
}
505510
close(fd);
506511

@@ -510,9 +515,11 @@ void ns_create(int argc, char **argv)
510515
fprintf(stderr, "open(%s): %m\n", pname);
511516
exit(1);
512517
}
513-
if (write(fd, GID_MAP, sizeof(GID_MAP)) < 0) {
514-
fprintf(stderr, "write(" GID_MAP "): %m\n");
515-
exit(1);
518+
519+
if (ext_gid_map) {
520+
dprintf(fd, "%s", ext_gid_map);
521+
} else {
522+
write(fd, GID_MAP, sizeof(GID_MAP) - 1);
516523
}
517524
close(fd);
518525
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{'flavor': 'h', 'flags': 'suid'}
1+
{'flags': 'suid ext-uid-map'}

0 commit comments

Comments
 (0)