2
1

0061-osdep-unix-getroot-Fix-potential-underflow.patch 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. From 050f09a5e16a935be4a4770f59f2a7ff977fc088 Mon Sep 17 00:00:00 2001
  2. From: Lidong Chen <lidong.chen@oracle.com>
  3. Date: Wed, 29 Jan 2025 06:48:38 +0000
  4. Subject: [PATCH] osdep/unix/getroot: Fix potential underflow
  5. The entry_len is initialized in grub_find_root_devices_from_mountinfo()
  6. to 0 before the while loop iterates through /proc/self/mountinfo. If the
  7. file is empty or contains only invalid entries entry_len remains
  8. 0 causing entry_len - 1 in the subsequent for loop initialization
  9. to underflow. To prevent this add a check to ensure entry_len > 0 before
  10. entering the for loop.
  11. Fixes: CID 473877
  12. Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
  13. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  14. Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
  15. Upstream: 66733f7c7dae889861ea3ef3ec0710811486019e
  16. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  17. ---
  18. grub-core/osdep/linux/getroot.c | 3 +++
  19. 1 file changed, 3 insertions(+)
  20. diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c
  21. index 7dd775d2a..527d4f0c5 100644
  22. --- a/grub-core/osdep/linux/getroot.c
  23. +++ b/grub-core/osdep/linux/getroot.c
  24. @@ -484,6 +484,9 @@ again:
  25. }
  26. }
  27. + if (!entry_len)
  28. + goto out;
  29. +
  30. /* Now scan visible mounts for the ones we're interested in. */
  31. for (i = entry_len - 1; i >= 0; i--)
  32. {
  33. --
  34. 2.50.1