From f134bca68b5b2283483b95567313736359e4612b Mon Sep 17 00:00:00 2001 From: Chris Mason Date: Fri, 22 May 2026 09:15:04 -0700 Subject: [PATCH] dissect-image: fix swallowed open() error in mountfsd_make_directory 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 --- src/shared/dissect-image.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 17c14db3ff..f1149cdaa6 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -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); }