2
1

0014-net-http-Fix-OOB-write-for-split-http-headers.patch 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. From 6bb49bda656e1121fd303cf3e69709172e267718 Mon Sep 17 00:00:00 2001
  2. From: Daniel Axtens <dja@axtens.net>
  3. Date: Tue, 8 Mar 2022 18:17:03 +1100
  4. Subject: [PATCH] net/http: Fix OOB write for split http headers
  5. GRUB has special code for handling an http header that is split
  6. across two packets.
  7. The code tracks the end of line by looking for a "\n" byte. The
  8. code for split headers has always advanced the pointer just past the
  9. end of the line, whereas the code that handles unsplit headers does
  10. not advance the pointer. This extra advance causes the length to be
  11. one greater, which breaks an assumption in parse_line(), leading to
  12. it writing a NUL byte one byte past the end of the buffer where we
  13. reconstruct the line from the two packets.
  14. It's conceivable that an attacker controlled set of packets could
  15. cause this to zero out the first byte of the "next" pointer of the
  16. grub_mm_region structure following the current_line buffer.
  17. Do not advance the pointer in the split header case.
  18. Fixes: CVE-2022-28734
  19. Signed-off-by: Daniel Axtens <dja@axtens.net>
  20. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  21. Upstream: ec6bfd3237394c1c7dbf2fd73417173318d22f4b
  22. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  23. ---
  24. grub-core/net/http.c | 4 +---
  25. 1 file changed, 1 insertion(+), 3 deletions(-)
  26. diff --git a/grub-core/net/http.c b/grub-core/net/http.c
  27. index b616cf40b..a19b0a205 100644
  28. --- a/grub-core/net/http.c
  29. +++ b/grub-core/net/http.c
  30. @@ -190,9 +190,7 @@ http_receive (grub_net_tcp_socket_t sock __attribute__ ((unused)),
  31. int have_line = 1;
  32. char *t;
  33. ptr = grub_memchr (nb->data, '\n', nb->tail - nb->data);
  34. - if (ptr)
  35. - ptr++;
  36. - else
  37. + if (ptr == NULL)
  38. {
  39. have_line = 0;
  40. ptr = (char *) nb->tail;
  41. --
  42. 2.41.0