]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dissect-image: fix wrong errno on pread failure
authorChris Mason <clm@meta.com>
Fri, 22 May 2026 16:23:03 +0000 (09:23 -0700)
committerLennart Poettering <lennart@amutable.com>
Fri, 22 May 2026 20:14:48 +0000 (22:14 +0200)
In acquire_sig_for_roothash() the pread() failure branch returns
-ENOMEM, which is copy-pasted from the malloc() check immediately
above it:

    _cleanup_free_ char *buf = new(char, partition_size+1);
    if (!buf)
            return -ENOMEM;

    ssize_t n = pread(fd, buf, partition_size, partition_offset);
    if (n < 0)
            return -ENOMEM;

pread() sets errno to the actual I/O failure (EIO, EINTR, EBADF,
...). Aliasing those to -ENOMEM misleads dissect_log_error() and
any caller that branches on the returned code; verity signature
lookup failures get reported as out-of-memory.

Fix by returning -errno from the pread() failure branch. The
malloc() branch above is correct and unchanged.

Fixes: 98ca65c36aa9 ("dissect: check that roothash in signature matches before selecting partition")
Assisted-by: kres (claude-opus-4-7)
Signed-off-by: Chris Mason <clm@meta.com>
src/shared/dissect-image.c

index f1149cdaa6def01da949df43b4c4655ef41b9468..db813a7eb4e336506f3f0578923b03ffcd907875 100644 (file)
@@ -717,7 +717,7 @@ static int acquire_sig_for_roothash(
 
         ssize_t n = pread(fd, buf, partition_size, partition_offset);
         if (n < 0)
-                return -ENOMEM;
+                return -errno;
         if ((uint64_t) n != partition_size)
                 return -EIO;