0016-fs-xfs-Fix-out-of-bounds-read.patch 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. From 854503d76e7dbc25f999d6be3e2ef4e8067f4152 Mon Sep 17 00:00:00 2001
  2. From: Michael Chang <mchang@suse.com>
  3. Date: Fri, 31 May 2024 15:14:57 +0800
  4. Subject: [PATCH] fs/xfs: Fix out-of-bounds read
  5. The number of records in the root key array read from disk was not being
  6. validated against the size of the root node. This could lead to an
  7. out-of-bounds read.
  8. This patch adds a check to ensure that the number of records in the root
  9. key array does not exceed the expected size of a root node read from
  10. disk. If this check detects an out-of-bounds condition the operation is
  11. aborted to prevent random errors due to metadata corruption.
  12. Reported-by: Daniel Axtens <dja@axtens.net>
  13. Signed-off-by: Michael Chang <mchang@suse.com>
  14. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  15. Upstream: 6ccc77b59d16578b10eaf8a4fe85c20b229f0d8a
  16. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  17. ---
  18. grub-core/fs/xfs.c | 11 +++++++++++
  19. 1 file changed, 11 insertions(+)
  20. diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c
  21. index bc2224dbb..d2d533531 100644
  22. --- a/grub-core/fs/xfs.c
  23. +++ b/grub-core/fs/xfs.c
  24. @@ -595,6 +595,17 @@ grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
  25. do
  26. {
  27. grub_uint64_t i;
  28. + grub_addr_t keys_end, data_end;
  29. +
  30. + if (grub_mul (sizeof (grub_uint64_t), nrec, &keys_end) ||
  31. + grub_add ((grub_addr_t) keys, keys_end, &keys_end) ||
  32. + grub_add ((grub_addr_t) node->data, node->data->data_size, &data_end) ||
  33. + keys_end > data_end)
  34. + {
  35. + grub_error (GRUB_ERR_BAD_FS, "invalid number of XFS root keys");
  36. + grub_free (leaf);
  37. + return 0;
  38. + }
  39. for (i = 0; i < nrec; i++)
  40. {
  41. --
  42. 2.50.1