]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shift-uid: close consumed directory fds on early return
authorLuca Boccassi <luca.boccassi@gmail.com>
Fri, 10 Jul 2026 17:48:35 +0000 (18:48 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 15 Jul 2026 20:13:24 +0000 (21:13 +0100)
recurse_fd() consumes each directory fd passed to it, but it has no
cleanup set up until after take_fdopendir() succeeds.
Errors and skipped procfs, sysfs, or read-only subtrees therefore leak the
incoming fd.

Follow-up for b1fb2d971c810e0bdf9ff0ae567a1c6c230e4e5d

src/shared/shift-uid.c

index e455306be91f9acca054e50c5ae115b1c130038a..e1c53dcb884dc8cf151628f96feb0918fae3958e 100644 (file)
@@ -295,8 +295,9 @@ static int is_fs_fully_userns_compatible(const struct statfs *sfs) {
                F_TYPE_EQUAL(sfs->f_type, SYSFS_MAGIC);
 }
 
-static int recurse_fd(int fd, const struct stat *st, uid_t shift, bool is_toplevel) {
+static int recurse_fd(int input_fd, const struct stat *st, uid_t shift, bool is_toplevel) {
         _cleanup_closedir_ DIR *d = NULL;
+        _cleanup_close_ int fd = input_fd;
         bool changed = false;
         struct statfs sfs;
         int r;