shift-uid: close consumed directory fds on early return

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 b1fb2d971c
This commit is contained in:
Luca Boccassi
2026-07-15 21:13:24 +01:00
parent 9dd2dab37e
commit c3eafb10a0
+2 -1
View 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;