XFS error handling fixes
cover XFS error handling fixes
This patchset fixes several issues with error handling in xfs module.
Egor Ignatov (3):
fs/xfs: Handle root inode read failure in grub_xfs_mount fs/xfs: Fix grub_xfs_iterate_dir return value in case of failure fs/xfs: Propagate incorrect inode error from grub_xfs_read_inode
grub-core/fs/xfs.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
Signature · 7 lines
2.42.4 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 1/3 fs/xfs: Handle root inode read failure in grub_xfs_mount
--- grub-core/fs/xfs.c | 2 ++ 1 file changed, 2 insertions(+)
grub-core/fs/xfs.c +2 -0
@@ -1053,6 +1053,8 @@ grub_xfs_mount (grub_disk_t disk) grub_cpu_to_be64(data->sblock.rootino));grub_xfs_read_inode (data, data->diropen.ino, &data->diropen.inode); +if (grub_errno) + goto fail;return data; fail:
Signature · 7 lines
2.42.4 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 1/3] fs/xfs: Handle root inode read failure in grub_xfs_mount
On Thu, Jan 23, 2025 at 08:44:13PM +0300, Egor Ignatov wrote:
I think you should explain in the commit message why this patch is needed.
Quoted 10 lines
Signed-off-by Egor Ignatov <[email protected]>--- grub-core/fs/xfs.c | 2 ++ 1 file changed, 2 insertions(+)grub-core/fs/xfs.c +0
-0
grub-core/fs/xfs.c grub_xfs_mount (grub_disk_t disk) · line 1056
Quoted 4 lines
grub-core/fs/xfs.c +1
-0@@ -1053,6 +1053,8 @@ grub_xfs_mount (grub_disk_t disk) grub_cpu_to_be64(data->sblock.rootino));grub_xfs_read_inode (data, data->diropen.ino, &data->diropen.inode); +if (grub_errno)
if (grub_errno != GRUB_ERR_NONE)
grub-core/fs/xfs.c grub_xfs_mount (grub_disk_t disk) · line 1060
Quoted 4 lines
grub-core/fs/xfs.c +1
-0+ goto fail;return data; fail:
If you fix these two issues you can add my RB.
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 2/3 fs/xfs: Fix grub_xfs_iterate_dir return value in case of failure
In reply to Egor IgnatovCommit ef7850c757 introduced multiple boundary checks in grub_xfs_iterate_dir() but handled the error incorrectly returning error code instead of 0.
Also change the error message so that it doesn't match the message in grub_xfs_read_inode().
--- grub-core/fs/xfs.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
grub-core/fs/xfs.c +9 -2
@@ -844,7 +844,11 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,grub_uint8_t c;if ((inopos + (smallino ?4 :8 )) > (grub_uint8_t *) dir +grub_xfs_fshelp_size (dir->data)) -return grub_error (GRUB_ERR_BAD_FS ,"not a correct XFS inode" ); + { +grub_error (GRUB_ERR_BAD_FS ,"invalid XFS inode" ); +return 0 ; + } +/* inopos might be unaligned. */ if (smallino)
@@ -963,7 +967,10 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir, filename = (char *)(direntry +1 );if (filename + direntry->len +1 > (char *) end) -return grub_error (GRUB_ERR_BAD_FS ,"invalid XFS directory entry" ); + { +grub_error (GRUB_ERR_BAD_FS ,"invalid XFS directory entry" ); +return 0 ; + }/* The byte after the filename is for the filetype, padding, or tag, which is not used by GRUB. So it can be overwritten. */
Signature · 7 lines
2.42.4 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 2/3] fs/xfs: Fix grub_xfs_iterate_dir return value in case of failure
Quoted 9 lines · Egor Ignatov
Commit
ef7850c757introduced multiple boundary checks ingrub_xfs_iterate_dir()but handled the error incorrectly returning error code instead of 0.Also change the error message so that it doesn't match the message in
grub_xfs_read_inode().Fixes ef7850c757 (fs/xfs: Fix issues found while fuzzing the XFS filesystem)Signed-off-by Egor Ignatov <[email protected]>
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 3/3 fs/xfs: Propagate incorrect inode error from grub_xfs_read_inode
In reply to Egor IgnatovThe incorrect inode error from grub_xfs_read_inode did not propagate because grub_print_error() resetted grub_errno, and grub_xfs_iterate_dir() did not handle it at all.
--- grub-core/fs/xfs.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
grub-core/fs/xfs.c +12 -2
@@ -780,7 +780,6 @@ static int iterate_dir_call_hook (grub_uint64_t ino, const char *filename, fdiro =grub_malloc (grub_xfs_fshelp_size (ctx->diro->data) +1 );if (!fdiro) { -grub_print_error ();return 0 ; }
@@ -792,7 +791,6 @@ static int iterate_dir_call_hook (grub_uint64_t ino, const char *filename, err =grub_xfs_read_inode (ctx->diro->data, ino, &fdiro->inode);if (err) { -grub_print_error ();grub_free (fdiro);return 0 ; }
@@ -832,9 +830,13 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,/* Synthesize the direntries for `.' and `..'. */ if (iterate_dir_call_hook (diro->ino,"." , &ctx))return 1 ; +else if (grub_errno) +return 0 ;if (iterate_dir_call_hook (parent,".." , &ctx))return 1 ; +else if (grub_errno) +return 0 ;for (i =0 ; i < head->count && (grub_uint8_t *) de < ((grub_uint8_t *) dir +grub_xfs_fshelp_size (dir->data)); i++)
@@ -875,6 +877,9 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir, } de->name[de->len] = c; +if (grub_errno) +return 0 ; + de =grub_xfs_inline_next_de (dir->data, head, de); }break ;
@@ -982,6 +987,11 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,grub_free (dirblock);return 1 ; } +else if (grub_errno) + { +grub_free (dirblock); +return 0 ; + }/* * The expected number of directory entries is only tracked for the
Signature · 7 lines
2.42.4 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 3/3] fs/xfs: Propagate incorrect inode error from grub_xfs_read_inode
Quoted 1 line · Egor Ignatov
The incorrect inode error from
grub_xfs_read_inodedid not propagate because
Something is off here. You drop two grub_print_error() calls but mention one after grub_xfs_read_inode() call only. So?
Quoted 1 line
grub_print_error()resettedgrub_errno, andgrub_xfs_iterate_dir()did not
Should not we restore grub_errno after grub_print_error() instead?
Quoted 28 lines
handle it at all.
Signed-off-by Egor Ignatov <[email protected]>--- grub-core/fs/xfs.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)grub-core/fs/xfs.c +0
-2@@ -780,7 +780,6 @@ static int iterate_dir_call_hook (grub_uint64_t ino, const char *filename, fdiro =grub_malloc (grub_xfs_fshelp_size (ctx->diro->data) +1 );if (!fdiro) { -grub_print_error ();return 0 ; }@@ -792,7 +791,6 @@ static int iterate_dir_call_hook (grub_uint64_t ino, const char *filename, err =grub_xfs_read_inode (ctx->diro->data, ino, &fdiro->inode);if (err) { -grub_print_error ();grub_free (fdiro);return 0 ; }
grub-core/fs/xfs.c grub_xfs_iterate_dir (grub_fshelp_node_t dir, · line 833
Quoted 4 lines
grub-core/fs/xfs.c +1
-0@@ -832,9 +830,13 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,/* Synthesize the direntries for `.' and `..'. */ if (iterate_dir_call_hook (diro->ino,"." , &ctx))return 1 ; +else if (grub_errno)
else if (grub_errno != GRUB_ERR_NONE)
grub-core/fs/xfs.c grub_xfs_iterate_dir (grub_fshelp_node_t dir, · line 838
Quoted 5 lines
grub-core/fs/xfs.c +2
-0+return 0 ;if (iterate_dir_call_hook (parent,".." , &ctx))return 1 ; +else if (grub_errno)
Ditto and below please...
Quoted 16 lines
grub-core/fs/xfs.c +4
-0+return 0 ;for (i =0 ; i < head->count && (grub_uint8_t *) de < ((grub_uint8_t *) dir +grub_xfs_fshelp_size (dir->data)); i++)@@ -875,6 +877,9 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir, } de->name[de->len] = c; +if (grub_errno) +return 0 ; + de =grub_xfs_inline_next_de (dir->data, head, de); }break ;@@ -982,6 +987,11 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,grub_free (dirblock);
grub-core/fs/xfs.c grub_xfs_iterate_dir (grub_fshelp_node_t dir, · line 997
Quoted 10 lines
grub-core/fs/xfs.c +5
-0return 1 ; } +else if (grub_errno) + { +grub_free (dirblock); +return 0 ; + }/* * The expected number of directory entries is only tracked for the
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 3/3] fs/xfs: Propagate incorrect inode error from grub_xfs_read_inode
Hi Daniel,
Sorry for the very late reply, and thanks for the review.
Quoted 5 lines · Daniel Kiper
Quoted 1 line · Egor Ignatov
The incorrect inode error from
grub_xfs_read_inodedid not propagate becauseSomething is off here. You drop two
grub_print_error()calls but mention one aftergrub_xfs_read_inode()call only. So?
Agree, needs clarification.
Quoted 3 lines
Quoted 1 line
grub_print_error()resettedgrub_errno, andgrub_xfs_iterate_dir()did notShould not we restore
grub_errnoaftergrub_print_error()instead?
I removed the grub_print_error() calls because with them and proper error propagation the same error message ended up being printed twice. That's why I think that grub_print_error() is redundant in iterate_dir_call_hook() in general. May be the better approach would be to split this changes into two patchs.
I would be glad to hear your opinion on this and I'm ready to send a v2 with your suggested changes.
Quoted 76 lines
Quoted 28 lines
handle it at all.
Signed-off-by Egor Ignatov <[email protected]>--- grub-core/fs/xfs.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)grub-core/fs/xfs.c +0
-2@@ -780,7 +780,6 @@ static int iterate_dir_call_hook (grub_uint64_t ino, const char *filename, fdiro =grub_malloc (grub_xfs_fshelp_size (ctx->diro->data) +1 );if (!fdiro) { -grub_print_error ();return 0 ; }@@ -792,7 +791,6 @@ static int iterate_dir_call_hook (grub_uint64_t ino, const char *filename, err =grub_xfs_read_inode (ctx->diro->data, ino, &fdiro->inode);if (err) { -grub_print_error ();grub_free (fdiro);return 0 ; }grub-core/fs/xfs.c grub_xfs_iterate_dir (grub_fshelp_node_t dir, · line 833
Quoted 4 lines
grub-core/fs/xfs.c +1
-0@@ -832,9 +830,13 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,/* Synthesize the direntries for `.' and `..'. */ if (iterate_dir_call_hook (diro->ino,"." , &ctx))return 1 ; +else if (grub_errno)else if (
grub_errno!=GRUB_ERR_NONE)grub-core/fs/xfs.c grub_xfs_iterate_dir (grub_fshelp_node_t dir, · line 838
Quoted 5 lines
grub-core/fs/xfs.c +2
-0+return 0 ;if (iterate_dir_call_hook (parent,".." , &ctx))return 1 ; +else if (grub_errno)Ditto and below please...
Quoted 16 lines
grub-core/fs/xfs.c +4
-0+return 0 ;for (i =0 ; i < head->count && (grub_uint8_t *) de < ((grub_uint8_t *) dir +grub_xfs_fshelp_size (dir->data)); i++)@@ -875,6 +877,9 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir, } de->name[de->len] = c; +if (grub_errno) +return 0 ; + de =grub_xfs_inline_next_de (dir->data, head, de); }break ;@@ -982,6 +987,11 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,grub_free (dirblock);grub-core/fs/xfs.c grub_xfs_iterate_dir (grub_fshelp_node_t dir, · line 997
Quoted 10 lines
grub-core/fs/xfs.c +5
-0return 1 ; } +else if (grub_errno) + { +grub_free (dirblock); +return 0 ; + }/* * The expected number of directory entries is only tracked for the Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 8 lines
Egor Ignatov ALT Linux Team _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
It would be good if someone circled back to the two unmerged patches in this series.
Quoted 11 lines · Egor Ignatov
This patchset fixes several issues with error handling in xfs module.
Egor Ignatov (3):
fs/xfs: Handle root inode read failure ingrub_xfs_mountfs/xfs: Fixgrub_xfs_iterate_dirreturn value in case of failure fs/xfs: Propagate incorrect inode error fromgrub_xfs_read_inodegrub-core/fs/xfs.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
Quoted 8 lines
--
2.42.4_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel