]> git.ipfire.org Git - thirdparty/systemd.git/commit
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)
commitfa0cd9b79f85dc6d24cd7d3f7c554b35bd5191fd
tree7ba8f4356658db4e819e29648eb6f46b7da8d67d
parentf134bca68b5b2283483b95567313736359e4612b
dissect-image: fix wrong errno on pread failure

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