]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dissect-image: fix swallowed open() error in mountfsd_make_directory
authorChris Mason <clm@meta.com>
Fri, 22 May 2026 16:15:04 +0000 (09:15 -0700)
committerLennart Poettering <lennart@amutable.com>
Fri, 22 May 2026 20:14:41 +0000 (22:14 +0200)
mountfsd_make_directory() opens the parent directory after a
successful path_extract_filename() call, but reports failure using
the stale path_extract_filename() return value:

    r = path_extract_filename(path, &dirname);
    if (r < 0)
            return log_debug_errno(r, ...);
    ...
    _cleanup_close_ int fd = open(parent, O_DIRECTORY|O_CLOEXEC);
    if (fd < 0)
            return log_debug_errno(r, "Failed to open '%s': %m", parent);

At the open() check site r holds the non-negative return of
path_extract_filename(). log_debug_errno() with a non-negative
first argument returns 0, so the function reports success even
though open() failed. Callers that pass a non-NULL ret_directory_fd
then consume an uninitialized fd value, and the diagnostic message
is suppressed because log_debug_errno(0, ...) emits nothing.

Fix by passing errno instead of r, matching the convention used in
mountfsd_mount_image() and mountfsd_mount_directory() in the same
file. The real open() failure (ENOENT, EACCES, ENOTDIR, EMFILE, ...)
now propagates to the caller and the log message is preserved.

Fixes: 1be8caa6be6f ("importd: support unpacking tarballs to foreign UID range")
Assisted-by: kres (claude-opus-4-7)
Signed-off-by: Chris Mason <clm@meta.com>
src/shared/dissect-image.c

index 17c14db3ffa192c524478772cc9425a5f5b0f636..f1149cdaa6def01da949df43b4c4655ef41b9468 100644 (file)
@@ -5509,7 +5509,7 @@ int mountfsd_make_directory(
 
         _cleanup_close_ int fd = open(parent, O_DIRECTORY|O_CLOEXEC);
         if (fd < 0)
-                return log_debug_errno(r, "Failed to open '%s': %m", parent);
+                return log_debug_errno(errno, "Failed to open '%s': %m", parent);
 
         return mountfsd_make_directory_fd(vl, fd, dirname, mode, flags, ret_directory_fd);
 }