Version in base suite: 4.17.4-2 Base version: shadow_4.17.4-2 Target version: shadow_4.17.4-2+deb13u1 Base file: /srv/ftp-master.debian.org/ftp/pool/main/s/shadow/shadow_4.17.4-2.dsc Target file: /srv/ftp-master.debian.org/policy/pool/main/s/shadow/shadow_4.17.4-2+deb13u1.dsc changelog | 7 patches/newuidmap-fd.patch | 176 +++++++++++++++++++++ patches/series | 2 patches/src-new-gu-idmap.c-Drop-fd-N.patch | 243 +++++++++++++++++++++++++++++ 4 files changed, 428 insertions(+) dpkg-source: warning: cannot verify inline signature for /srv/release.debian.org/tmp/tmp5b7n259k/shadow_4.17.4-2.dsc: no acceptable signature found dpkg-source: warning: cannot verify inline signature for /srv/release.debian.org/tmp/tmp5b7n259k/shadow_4.17.4-2+deb13u1.dsc: no acceptable signature found diff -Nru shadow-4.17.4/debian/changelog shadow-4.17.4/debian/changelog --- shadow-4.17.4/debian/changelog 2025-04-19 10:20:28.000000000 +0000 +++ shadow-4.17.4/debian/changelog 2026-11-17 10:10:39.000000000 +0000 @@ -1,3 +1,10 @@ +shadow (1:4.17.4-2+deb13u1) trixie-security; urgency=medium + + * Fix security issue in newuidmap/newgidmap. + Support for newuidmap/newgidmap pid: was removed. + + -- Chris Hofstaedtler Tue, 17 Nov 2026 11:10:39 +0100 + shadow (1:4.17.4-2) unstable; urgency=medium * Allow LOGIN_ENV_SAFELIST (from util-linux) in /etc/login.defs. diff -Nru shadow-4.17.4/debian/patches/newuidmap-fd.patch shadow-4.17.4/debian/patches/newuidmap-fd.patch --- shadow-4.17.4/debian/patches/newuidmap-fd.patch 1970-01-01 00:00:00.000000000 +0000 +++ shadow-4.17.4/debian/patches/newuidmap-fd.patch 2026-11-17 10:10:39.000000000 +0000 @@ -0,0 +1,176 @@ +From: "Serge E. Hallyn" +Date: Tue, 17 Nov 2026 10:55:41 +0100 +Subject: newuidmap fd + +newuidmap and newgidmap accept fd:N, where N is an open fd to a +/proc/pid directory, in place of a numeric pid value, to specify +the process on which to act. The intent is to avoid cases where +the process dies and pid is quickly wrapped around, between +check and use. + +We check that the /proc/pid directory fd is good, and generally +we can trust that /proc must have been setup by a trusted admin, +and any namespace shenanigans will land the caller in a namespace +without privilege to write to the original /proc. + +Make this even safer by enforcing that the openat() of a file under +the fd does not follow any symlinks or bind mounts, which, for +instance, a colluding root user could have left in place. + +openat2(2) has been around for many years, so if it is not available, +we simply fail to compile. + +Reported-by: Dickson Wu +Co-developed-by: Serge Hallyn +Message-ID: +Signed-off-by: Serge Hallyn +Message-ID: +[alx: Moved to under lib/fs/] +[alx: Remove ENOSYS, and just fail to compile instead] +[alx: Add my_openat[__]() wrappers] +[alx: Rename parameter for consistency with openat(2) manual page] +[alx: Refer to openat(2) for documentation] +Tested-by: Dickson Wu +Signed-off-by: Alejandro Colomar +Gbp-Pq Topic: upstream +--- + lib/Makefile.am | 2 ++ + lib/fs/open/open.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ + lib/fs/open/open.h | 16 ++++++++++++++++ + lib/idmapping.c | 3 ++- + src/newgidmap.c | 3 ++- + 5 files changed, 70 insertions(+), 2 deletions(-) + create mode 100644 lib/fs/open/open.c + create mode 100644 lib/fs/open/open.h + +diff --git a/lib/Makefile.am b/lib/Makefile.am +index 307e704..7aaa8a0 100644 +--- a/lib/Makefile.am ++++ b/lib/Makefile.am +@@ -103,6 +103,8 @@ libshadow_la_SOURCES = \ + find_new_sub_gids.c \ + find_new_sub_uids.c \ + fputsx.c \ ++ fs/open/open.c \ ++ fs/open/open.h \ + fs/readlink/areadlink.c \ + fs/readlink/areadlink.h \ + fs/readlink/readlinknul.c \ +diff --git a/lib/fs/open/open.c b/lib/fs/open/open.c +new file mode 100644 +index 0000000..e38eefc +--- /dev/null ++++ b/lib/fs/open/open.c +@@ -0,0 +1,48 @@ ++// SPDX-FileCopyrightText: 2026, Serge Hallyn ++// SPDX-FileCopyrightText: 2026, Alejandro Colomar ++// SPDX-License-Identifier: BSD-3-Clause ++ ++ ++#include "config.h" ++ ++#include "fs/open/open.h" ++ ++#include ++#include ++#include ++#include ++#include ++ ++ ++ ++// openat2(2) ++#define my_openat2(d, p, h) my_openat2__(d, p, h, sizeof(struct open_how)) ++ ++ ++static int my_openat2__(int dirfd, const char *path, struct open_how *how, ++ size_t size); ++ ++ ++/* ++ * openat(2), but ensuring that there are no bind mounts or symlinks ++ * redirecting the path walk. ++ * The arguments are the same as for openat(2). ++ */ ++int ++samedev_openat(int dirfd, const char *path, int flags) ++{ ++ struct open_how how = { ++ .flags = flags, ++ .resolve = RESOLVE_NO_XDEV | RESOLVE_NO_SYMLINKS | ++ RESOLVE_NO_MAGICLINKS, ++ }; ++ ++ return my_openat2(dirfd, path, &how); ++} ++ ++ ++static int ++my_openat2__(int dirfd, const char *path, struct open_how *how, size_t size) ++{ ++ return syscall(SYS_openat2, dirfd, path, how, size); ++} +diff --git a/lib/fs/open/open.h b/lib/fs/open/open.h +new file mode 100644 +index 0000000..e9e556d +--- /dev/null ++++ b/lib/fs/open/open.h +@@ -0,0 +1,16 @@ ++// SPDX-FileCopyrightText: 2026, Serge Hallyn ++// SPDX-FileCopyrightText: 2026, Alejandro Colomar ++// SPDX-License-Identifier: BSD-3-Clause ++ ++ ++#ifndef SHADOW_INCLUDE_LIB_FS_OPEN_OPEN_H_ ++#define SHADOW_INCLUDE_LIB_FS_OPEN_OPEN_H_ ++ ++ ++#include "config.h" ++ ++ ++extern int samedev_openat(int dirfd, const char *path, int flags); ++ ++ ++#endif // include guard +diff --git a/lib/idmapping.c b/lib/idmapping.c +index ef685f3..d5fceac 100644 +--- a/lib/idmapping.c ++++ b/lib/idmapping.c +@@ -20,6 +20,7 @@ + #include "alloc/calloc.h" + #include "alloc/x/xmalloc.h" + #include "atoi/a2i/a2u.h" ++#include "fs/open/open.h" + #include "idmapping.h" + #include "prototypes.h" + #include "shadowlog.h" +@@ -191,7 +192,7 @@ void write_mapping(int proc_dir_fd, int ranges, const struct map_range *mappings + } + + /* Write the mapping to the mapping file */ +- fd = openat(proc_dir_fd, map_file, O_WRONLY); ++ fd = samedev_openat(proc_dir_fd, map_file, O_WRONLY); + if (fd < 0) { + fprintf(log_get_logfd(), _("%s: open of %s failed: %s\n"), + log_get_progname(), map_file, strerror(errno)); +diff --git a/src/newgidmap.c b/src/newgidmap.c +index b1bf80e..a95d30f 100644 +--- a/src/newgidmap.c ++++ b/src/newgidmap.c +@@ -17,6 +17,7 @@ + #include "prototypes.h" + #include "subordinateio.h" + #include "getdef.h" ++#include "fs/open/open.h" + #include "idmapping.h" + #include "shadowlog.h" + +@@ -89,7 +90,7 @@ static void write_setgroups(int proc_dir_fd, bool allow_setgroups) + if (allow_setgroups) + return; + +- setgroups_fd = openat(proc_dir_fd, "setgroups", O_RDWR|O_CLOEXEC); ++ setgroups_fd = samedev_openat(proc_dir_fd, "setgroups", O_RDWR|O_CLOEXEC); + if (setgroups_fd < 0) { + /* + * If it's an ENOENT then we are on too old a kernel for the setgroups diff -Nru shadow-4.17.4/debian/patches/series shadow-4.17.4/debian/patches/series --- shadow-4.17.4/debian/patches/series 2025-04-19 10:19:43.000000000 +0000 +++ shadow-4.17.4/debian/patches/series 2026-11-17 10:10:39.000000000 +0000 @@ -11,3 +11,5 @@ debian/configure.ac-align-exec_prefix-with-prefix.patch upstream/Accept-usr-sbin-nologin-as-an-alternate-to-sbin-nologin.patch upstream/Add-LOGIN_ENV_SAFELIST-to-FOREIGNDEFS.patch +newuidmap-fd.patch +src-new-gu-idmap.c-Drop-fd-N.patch diff -Nru shadow-4.17.4/debian/patches/src-new-gu-idmap.c-Drop-fd-N.patch shadow-4.17.4/debian/patches/src-new-gu-idmap.c-Drop-fd-N.patch --- shadow-4.17.4/debian/patches/src-new-gu-idmap.c-Drop-fd-N.patch 1970-01-01 00:00:00.000000000 +0000 +++ shadow-4.17.4/debian/patches/src-new-gu-idmap.c-Drop-fd-N.patch 2026-11-17 10:10:39.000000000 +0000 @@ -0,0 +1,243 @@ +From: "Serge E. Hallyn" +Date: Tue, 17 Nov 2026 10:55:41 +0100 +Subject: src/new[gu]idmap.c: Drop fd:N + +Nothing uses it, and it doesn't actually add anything: we keep the +/proc/pid fd open anyway, and so are already protected from any +pid wraparound race. + +The process id may get reused while we hold open the /proc/pid. +However, so long as we use openat under the fd we have for /proc/pid, +we are referencing the old process. So when we try to +openat(fd, "setgroups") or whatever, the call will fail. + +Signed-off-by: Serge Hallyn +Signed-off-by: Alejandro Colomar +Gbp-Pq Topic: upstream +--- + lib/atoi/getnum.c | 1 - + lib/atoi/getnum.h | 9 --------- + lib/get_pid.c | 32 -------------------------------- + lib/prototypes.h | 1 - + man/newgidmap.1.xml | 11 ----------- + man/newuidmap.1.xml | 11 ----------- + src/newgidmap.c | 17 +++++------------ + src/newuidmap.c | 18 ++++++------------ + 8 files changed, 11 insertions(+), 89 deletions(-) + +diff --git a/lib/atoi/getnum.c b/lib/atoi/getnum.c +index 3c67eb2..9eb95e5 100644 +--- a/lib/atoi/getnum.c ++++ b/lib/atoi/getnum.c +@@ -10,7 +10,6 @@ + #include "atoi/getnum.h" + + +-extern inline int get_fd(const char *restrict fdstr, int *restrict fd); + extern inline int get_gid(const char *restrict gidstr, gid_t *restrict gid); + extern inline int get_pid(const char *restrict pidstr, pid_t *restrict pid); + extern inline int get_uid(const char *restrict uidstr, uid_t *restrict uid); +diff --git a/lib/atoi/getnum.h b/lib/atoi/getnum.h +index 33d4876..d2ea05f 100644 +--- a/lib/atoi/getnum.h ++++ b/lib/atoi/getnum.h +@@ -19,8 +19,6 @@ + #include "typetraits.h" + + +-ATTR_STRING(1) ATTR_ACCESS(write_only, 2) +-inline int get_fd(const char *restrict fdstr, int *restrict fd); + ATTR_STRING(1) ATTR_ACCESS(write_only, 2) + inline int get_gid(const char *restrict gidstr, gid_t *restrict gid); + ATTR_STRING(1) ATTR_ACCESS(write_only, 2) +@@ -29,13 +27,6 @@ ATTR_STRING(1) ATTR_ACCESS(write_only, 2) + inline int get_uid(const char *restrict uidstr, uid_t *restrict uid); + + +-inline int +-get_fd(const char *restrict fdstr, int *restrict fd) +-{ +- return a2si(fd, fdstr, NULL, 10, 0, INT_MAX); +-} +- +- + inline int + get_gid(const char *restrict gidstr, gid_t *restrict gid) + { +diff --git a/lib/get_pid.c b/lib/get_pid.c +index f4d31cf..c3af172 100644 +--- a/lib/get_pid.c ++++ b/lib/get_pid.c +@@ -17,38 +17,6 @@ + #include "string/sprintf/snprintf.h" + + +-/* +- * If use passed in fd:4 as an argument, then return the +- * value '4', the fd to use. +- * On error, return -1. +- */ +-int get_pidfd_from_fd(const char *pidfdstr) +-{ +- int pidfd; +- struct stat st; +- dev_t proc_st_dev, proc_st_rdev; +- +- if (get_fd(pidfdstr, &pidfd) == -1) +- return -1; +- +- if (stat("/proc/self/uid_map", &st) < 0) { +- return -1; +- } +- +- proc_st_dev = st.st_dev; +- proc_st_rdev = st.st_rdev; +- +- if (fstat(pidfd, &st) < 0) { +- return -1; +- } +- +- if (st.st_dev != proc_st_dev || st.st_rdev != proc_st_rdev) { +- return -1; +- } +- +- return pidfd; +-} +- + int open_pidfd(const char *pidstr) + { + int proc_dir_fd; +diff --git a/lib/prototypes.h b/lib/prototypes.h +index 003fef0..f3d9f45 100644 +--- a/lib/prototypes.h ++++ b/lib/prototypes.h +@@ -146,7 +146,6 @@ extern int find_new_sub_uids (uid_t *range_start, unsigned long *range_count); + extern /*@only@*//*@null@*/struct group *getgr_nam_gid (/*@null@*/const char *grname); + + /* get_pid.c */ +-extern int get_pidfd_from_fd(const char *pidfdstr); + extern int open_pidfd(const char *pidstr); + + /* getrange */ +diff --git a/man/newgidmap.1.xml b/man/newgidmap.1.xml +index e5b770e..e4ebc69 100644 +--- a/man/newgidmap.1.xml ++++ b/man/newgidmap.1.xml +@@ -116,17 +116,6 @@ + + Note that newgidmap may be used only once for a given process. + +- +- Instead of an integer process id, the first argument may be +- specified as fd:N, where the integer N +- is the file descriptor number for the calling process's opened +- file descriptor for the directory /proc/[pid]. +- In this case, newgidmap will use +- openat2 +- to open the gid_map file under that +- directory, avoiding a TOCTTOU in case the process exits and +- the pid is immediately reused. +- + + + +diff --git a/man/newuidmap.1.xml b/man/newuidmap.1.xml +index 7aed0d5..f5cb5b4 100644 +--- a/man/newuidmap.1.xml ++++ b/man/newuidmap.1.xml +@@ -116,17 +116,6 @@ + + Note that newuidmap may be used only once for a given process. + +- +- Instead of an integer process id, the first argument may be +- specified as fd:N, where the integer N +- is the file descriptor number for the calling process's opened +- file descriptor for the directory /proc/[pid]. +- In this case, newuidmap will use +- openat2 +- to open the uid_map file under that +- directory, avoiding a TOCTTOU in case the process exits and +- the pid is immediately reused. +- + + + +diff --git a/src/newgidmap.c b/src/newgidmap.c +index a95d30f..e45d2a6 100644 +--- a/src/newgidmap.c ++++ b/src/newgidmap.c +@@ -70,7 +70,7 @@ static void verify_ranges(struct passwd *pw, int ranges, + + static void usage(void) + { +- fprintf(stderr, _("usage: %s [] [ ] ... \n"), Prog); ++ fprintf(stderr, _("usage: %s [ ] ... \n"), Prog); + exit(EXIT_FAILURE); + } + +@@ -167,17 +167,10 @@ int main(int argc, char **argv) + */ + + target_str = argv[1]; +- if (strlen(target_str) > 3 && strncmp(target_str, "fd:", 3) == 0) { +- /* the user passed in a /proc/pid fd for the process */ +- target_str = &target_str[3]; +- proc_dir_fd = get_pidfd_from_fd(target_str); +- if (proc_dir_fd < 0) +- usage(); +- } else { +- proc_dir_fd = open_pidfd(target_str); +- if (proc_dir_fd < 0) +- usage(); +- } ++ proc_dir_fd = open_pidfd(target_str); ++ if (proc_dir_fd < 0) ++ usage(); ++ + /* Who am I? */ + pw = get_my_pwent (); + if (NULL == pw) { +diff --git a/src/newuidmap.c b/src/newuidmap.c +index 8deb06f..8b5bc10 100644 +--- a/src/newuidmap.c ++++ b/src/newuidmap.c +@@ -19,6 +19,8 @@ + #include "getdef.h" + #include "idmapping.h" + #include "shadowlog.h" ++#include "subordinateio.h" ++ + + /* + * Global variables +@@ -64,7 +66,7 @@ static void verify_ranges(struct passwd *pw, int ranges, + + static void usage(void) + { +- fprintf(stderr, _("usage: %s [|fd:] [ ] ... \n"), Prog); ++ fprintf(stderr, _("usage: %s [ ] ... \n"), Prog); + exit(EXIT_FAILURE); + } + +@@ -94,17 +96,9 @@ int main(int argc, char **argv) + /* Find the process that needs its user namespace + * uid mapping set. + */ +- if (strlen(target_str) > 3 && strncmp(target_str, "fd:", 3) == 0) { +- /* the user passed in a /proc/pid fd for the process */ +- target_str = &target_str[3]; +- proc_dir_fd = get_pidfd_from_fd(target_str); +- if (proc_dir_fd < 0) +- usage(); +- } else { +- proc_dir_fd = open_pidfd(target_str); +- if (proc_dir_fd < 0) +- usage(); +- } ++ proc_dir_fd = open_pidfd(target_str); ++ if (proc_dir_fd < 0) ++ usage(); + + /* Who am I? */ + pw = get_my_pwent ();