0037-gettext-Integer-overflow-leads-to-heap-OOB-write.patch 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. From dfe673e457e9eb5c7c0c68d8385ba176476de7d7 Mon Sep 17 00:00:00 2001
  2. From: Lidong Chen <lidong.chen@oracle.com>
  3. Date: Fri, 22 Nov 2024 06:27:57 +0000
  4. Subject: [PATCH] gettext: Integer overflow leads to heap OOB write
  5. The size calculation of the translation buffer in
  6. grub_gettext_getstr_from_position() may overflow
  7. to 0 leading to heap OOB write. This patch fixes
  8. the issue by using grub_add() and checking for
  9. an overflow.
  10. Fixes: CVE-2024-45777
  11. Reported-by: Nils Langius <nils@langius.de>
  12. Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
  13. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  14. Reviewed-by: Alec Brown <alec.r.brown@oracle.com>
  15. Upstream: b970a5ed967816bbca8225994cd0ee2557bad515
  16. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  17. ---
  18. grub-core/gettext/gettext.c | 7 ++++++-
  19. 1 file changed, 6 insertions(+), 1 deletion(-)
  20. diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c
  21. index 63bb1ab73..9ffc73428 100644
  22. --- a/grub-core/gettext/gettext.c
  23. +++ b/grub-core/gettext/gettext.c
  24. @@ -26,6 +26,7 @@
  25. #include <grub/file.h>
  26. #include <grub/kernel.h>
  27. #include <grub/i18n.h>
  28. +#include <grub/safemath.h>
  29. GRUB_MOD_LICENSE ("GPLv3+");
  30. @@ -99,6 +100,7 @@ grub_gettext_getstr_from_position (struct grub_gettext_context *ctx,
  31. char *translation;
  32. struct string_descriptor desc;
  33. grub_err_t err;
  34. + grub_size_t alloc_sz;
  35. internal_position = (off + position * sizeof (desc));
  36. @@ -109,7 +111,10 @@ grub_gettext_getstr_from_position (struct grub_gettext_context *ctx,
  37. length = grub_cpu_to_le32 (desc.length);
  38. offset = grub_cpu_to_le32 (desc.offset);
  39. - translation = grub_malloc (length + 1);
  40. + if (grub_add (length, 1, &alloc_sz))
  41. + return NULL;
  42. +
  43. + translation = grub_malloc (alloc_sz);
  44. if (!translation)
  45. return NULL;
  46. --
  47. 2.50.1