Skip to contentSkip to conversation

fs/xfs: Incorrect short form directory data boundary check

PATCH In review Lidong Chen 4 participants 5 messages Sep 28, 2023 – Oct 18, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/xfs: Incorrect short form directory data boundary check

After parsing of the current entry, the entry pointer is advanced to the next entry at the end of the 'for' loop. In case where the last entry is at the end of the data boundary, the advanced entry pointer can point off the data boundary. The subsequent boundary check for the advanced entry pointer can cause a failure.

The fix is to include the boundary check into the 'for' loop condition.

---
 grub-core/fs/xfs.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
grub-core/fs/xfs.c +2 -5
index b91cd32b4..ebf962793 100644
@@ -810,7 +810,8 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
 	if (iterate_dir_call_hook (parent, "..", &ctx))
 	  return 1;
 
-	for (i = 0; i < head->count; i++)
+	for (i = 0; i < head->count &&
+	     (grub_uint8_t *) de < ((grub_uint8_t *) dir + grub_xfs_fshelp_size (dir->data)); i++)
 	  {
 	    grub_uint64_t ino;
 	    grub_uint8_t *inopos = grub_xfs_inline_de_inopos(dir->data, de);
@@ -845,10 +846,6 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
 	    de->name[de->len] = c;
 
 	    de = grub_xfs_inline_next_de(dir->data, head, de);
-
-	    if ((grub_uint8_t *) de >= (grub_uint8_t *) dir + grub_xfs_fshelp_size (dir->data))
-	      return grub_error (GRUB_ERR_BAD_FS, "invalid XFS directory entry");
-
 	  }
 	break;
       }
Signature · 7 lines
2.30.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#1 lore raw

Jon, may I ask you to take a look at this patch? Does not it conflict with your XFS patch [1].

Daniel

[1] https://lists.gnu.org/archive/html/grub-devel/2023-09/msg00110.html

Quoted 29 lines · Lidong Chen

After parsing of the current entry, the entry pointer is advanced to the next entry at the end of the 'for' loop. In case where the last entry is at the end of the data boundary, the advanced entry pointer can point off the data boundary. The subsequent boundary check for the advanced entry pointer can cause a failure.

The fix is to include the boundary check into the 'for' loop condition.

---
 grub-core/fs/xfs.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
grub-core/fs/xfs.c +2 -1
index b91cd32b4..ebf962793 100644
@@ -810,7 +810,8 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
 	if (iterate_dir_call_hook (parent, "..", &ctx))
 	  return 1;
 
-	for (i = 0; i < head->count; i++)
+	for (i = 0; i < head->count &&
+	     (grub_uint8_t *) de < ((grub_uint8_t *) dir + grub_xfs_fshelp_size (dir->data)); i++)
 	  {
 	    grub_uint64_t ino;
 	    grub_uint8_t *inopos = grub_xfs_inline_de_inopos(dir->data, de);

grub-core/fs/xfs.c grub_xfs_iterate_dir (grub_fshelp_node_t dir, · line 851

Quoted 10 lines
grub-core/fs/xfs.c +0 -4
@@ -845,10 +846,6 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
 	    de->name[de->len] = c;
 
 	    de = grub_xfs_inline_next_de(dir->data, head, de);
-
-	    if ((grub_uint8_t *) de >= (grub_uint8_t *) dir + grub_xfs_fshelp_size (dir->data))
-	      return grub_error (GRUB_ERR_BAD_FS, "invalid XFS directory entry");
-
 	  }
 	break;
       }

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw
Quoted 3 lines · Daniel Kiper

Jon, may I ask you to take a look at this patch? Does not it conflict with your XFS patch [1].

They are similar but distinct code paths. This patch is for the XFS_INODE_FORMAT_INO case, my patch is for the XFS_INODE_FORMAT_EXT and XFS_INODE_FORMAT_BTREE cases.

Signature · 8 lines
Jon
Doge Wrangler
X(7): A program for managing terminal windows. See also screen(1) and tmux(1).

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#3 lore raw
Quoted 7 lines · Jon DeVree
Quoted 2 lines · Daniel Kiper

Jon, may I ask you to take a look at this patch? Does not it conflict with your XFS patch [1].

They are similar but distinct code paths. This patch is for the XFS_INODE_FORMAT_INO case, my patch is for the XFS_INODE_FORMAT_EXT and XFS_INODE_FORMAT_BTREE cases.

Thanks for clarification. This is more or less what I expected.

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Reviewed-by on v1 1/1
#4 lore raw
In reply to Lidong Chen
Quoted 10 lines · Lidong Chen

After parsing of the current entry, the entry pointer is advanced to the next entry at the end of the 'for' loop. In case where the last entry is at the end of the data boundary, the advanced entry pointer can point off the data boundary. The subsequent boundary check for the advanced entry pointer can cause a failure.

The fix is to include the boundary check into the 'for' loop condition.

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel