gzio: Avoid spurious failures
PATCH v2 1/1 gzio: Avoid spurious failures
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.
Add a grub_debug_errno() macro to print existing grub_errno messages at the start of the function, and reset grub_errno to avoid such errors.
---
v2:
Add grub_debug_errno helper
Separate debug from reset.
--- grub-core/io/gzio.c | 4 ++++ include/grub/err.h | 9 +++++++++ 2 files changed, 13 insertions(+)
grub-core/io/gzio.c +4 -0
@@ -1294,6 +1294,10 @@ 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. */ +grub_debug_errno (); + grub_errno =GRUB_ERR_NONE ; +/* Do we reset decompression to the beginning of the file? */ if (gzio->saved_offset > offset +WSIZE )initialize_tables (gzio);
include/grub/err.h +9 -0
@@ -96,4 +96,13 @@ extern int EXPORT_VAR(grub_err_printed_errors);int grub_err_printf (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF ,1 ,2 ))); +#define grub_debug_errno () \ +do { \ + if ( grub_errno != GRUB_ERR_NONE ) \ + { \ + grub_dprintf ("errno", "%s: clearing pre-exising errmsg %s\n", \ + __func__, grub_errmsg); \ + } \ +} while (0); +#endif /* ! GRUB_ERR_HEADER */
Signature · 7 lines
2.41.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 5 lines · Jason Andryuk
grub_gzio_read_real()usesgrub_errnoto identify decompression failures when the function completes. Its callees ingzio.care void-returning functions that setgrub_errnoon their exit paths.
Quoted 8 lines
A Fedora 38 machine was observed to fail
multiboot2 /xen.gzwith "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_errnois set toGRUB_ERR_UNKNOWN_DEVICE. This pre-existinggrub_errnocauses an otherwise successfulgrub_gzio_read_real()call to return error.
This bus is likely to create other problems as well. Why not fix it? If this error is meant to be ignored rather than stop loading, then it should be discarded early, possibly printed. If it should stop loading then this should really stop and not even get here
Quoted 55 lines
Add a
grub_debug_errno()macro to print existinggrub_errnomessages at the start of the function, and resetgrub_errnoto avoid such errors.Signed-off-by Jason Andryuk <[email protected]>---
v2:
Addgrub_debug_errnohelper
Separate debug from reset.--- grub-core/io/gzio.c | 4 ++++ include/grub/err.h | 9 +++++++++ 2 files changed, 13 insertions(+)grub-core/io/gzio.c +4
-0@@ -1294,6 +1294,10 @@ 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. */ +grub_debug_errno (); + grub_errno =GRUB_ERR_NONE ; +/* Do we reset decompression to the beginning of the file? */ if (gzio->saved_offset > offset +WSIZE )initialize_tables (gzio);include/grub/err.h +9
-1@@ -96,4 +96,13 @@ extern int EXPORT_VAR(grub_err_printed_errors);int grub_err_printf (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF ,1 ,2 ))); +#define grub_debug_errno () \ +do { \ + if ( grub_errno != GRUB_ERR_NONE ) \ + { \ + grub_dprintf ("errno", "%s: clearing pre-exising errmsg %s\n", \ + __func__, grub_errmsg); \ + } \ +} while (0); +#endif /* ! GRUB_ERR_HEADER */ --2.41.0
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 7 lines
Regards Vladimir 'phcoder' Serbinenko _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 10 lines · Vladimir 'phcoder' Serbinenko
Quoted 9 lines · Jason Andryuk
grub_gzio_read_real()usesgrub_errnoto identify decompression failures when the function completes. Its callees ingzio.care void-returning functions that setgrub_errnoon their exit paths.A Fedora 38 machine was observed to fail
multiboot2 /xen.gzwith "premature end of file". xen.gz was well formed and could be successfully gunzip-ed in Linux.
Quoted 8 lines
Quoted 4 lines
The TPM is flaky and produces errors when the verifier tries to extend PCRs with measurements. Logs show "Unkown TPM error" and
grub_errnois set toGRUB_ERR_UNKNOWN_DEVICE. This pre-existinggrub_errnocauses an otherwise successfulgrub_gzio_read_real()call to return error.This bus is likely to create other problems as well. Why not fix it? If this error is meant to be ignored rather than stop loading, then it should be discarded early, possibly printed. If it should stop loading then this should really stop and not even get here
Jason, this makes me wonder what GRUB version you use. Do you have this commit afdef4a56 (tpm: Enable boot despite unknown firmware failure)? I am not sure I did not ask you about this earlier...
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel