grub_gzio_read_real() uses grub_errno to identify decompression failures when the function completes. Its callees in gzio.c are void-returning functions that set grub_errno on their exit paths.
A Fedora 38 machine was observed to fail `multiboot2 /xen.gz` with "premature end of file". xen.gz was well formed and could be successfully gunzip-ed in Linux. The TPM is flaky and produces errors when the verifier tries to extend PCRs with measurements. Logs show "Unkown TPM error" and grub_errno is set to GRUB_ERR_UNKNOWN_DEVICE. This pre-existing grub_errno causes an otherwise successful grub_gzio_read_real() call to return error. Clear grub_errno at the start of the function to avoid such errors. Signed-off-by: Jason Andryuk <[email protected]> --- grub-core/io/gzio.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c index ca9355751..1e31a8255 100644 --- a/grub-core/io/gzio.c +++ b/grub-core/io/gzio.c @@ -1294,6 +1294,14 @@ grub_gzio_read_real (grub_gzio_t gzio, grub_off_t offset, { grub_ssize_t ret = 0; + /* Avoid spurious failures on exit when grub_errno is already set. */ + if (grub_errno != GRUB_ERR_NONE) + { + grub_dprintf ("gzio", "%s: clearing pre-exising errmsg %s\n", + __func__, grub_errmsg); + grub_errno = GRUB_ERR_NONE; + } + /* Do we reset decompression to the beginning of the file? */ if (gzio->saved_offset > offset + WSIZE) initialize_tables (gzio); -- 2.41.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
