0015-fs-ext2-Fix-out-of-bounds-read-for-inline-extents.patch 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. From 7da8e2e23db5f1ddb9c4dc992c69349149163c4c Mon Sep 17 00:00:00 2001
  2. From: Michael Chang <mchang@suse.com>
  3. Date: Fri, 31 May 2024 15:14:23 +0800
  4. Subject: [PATCH] fs/ext2: Fix out-of-bounds read for inline extents
  5. When inline extents are used, i.e. the extent tree depth equals zero,
  6. a maximum of four entries can fit into the inode's data block. If the
  7. extent header states a number of entries greater than four the current
  8. ext2 implementation causes an out-of-bounds read. Fix this issue by
  9. capping the number of extents to four when reading inline extents.
  10. Reported-by: Daniel Axtens <dja@axtens.net>
  11. Signed-off-by: Michael Chang <mchang@suse.com>
  12. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  13. Upstream: 7e2f750f0a795c4d64ec7dc7591edac8da2e978c
  14. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  15. ---
  16. grub-core/fs/ext2.c | 10 +++++++++-
  17. 1 file changed, 9 insertions(+), 1 deletion(-)
  18. diff --git a/grub-core/fs/ext2.c b/grub-core/fs/ext2.c
  19. index e1cc5e62a..3f9f6b208 100644
  20. --- a/grub-core/fs/ext2.c
  21. +++ b/grub-core/fs/ext2.c
  22. @@ -495,6 +495,8 @@ grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
  23. struct grub_ext4_extent *ext;
  24. int i;
  25. grub_disk_addr_t ret;
  26. + grub_uint16_t nent;
  27. + const grub_uint16_t max_inline_ext = sizeof (inode->blocks) / sizeof (*ext) - 1; /* Minus 1 extent header. */
  28. if (grub_ext4_find_leaf (data, (struct grub_ext4_extent_header *) inode->blocks.dir_blocks,
  29. fileblock, &leaf) != GRUB_ERR_NONE)
  30. @@ -508,7 +510,13 @@ grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
  31. return 0;
  32. ext = (struct grub_ext4_extent *) (leaf + 1);
  33. - for (i = 0; i < grub_le_to_cpu16 (leaf->entries); i++)
  34. +
  35. + nent = grub_le_to_cpu16 (leaf->entries);
  36. +
  37. + if (leaf->depth == 0)
  38. + nent = grub_min (nent, max_inline_ext);
  39. +
  40. + for (i = 0; i < nent; i++)
  41. {
  42. if (fileblock < grub_le_to_cpu32 (ext[i].block))
  43. break;
  44. --
  45. 2.50.1