f0ad2aa
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f0ad2aa
From: Daniel Axtens <dja@axtens.net>
f0ad2aa
Date: Tue, 8 Mar 2022 18:17:03 +1100
f0ad2aa
Subject: [PATCH] net/http: Fix OOB write for split http headers
f0ad2aa
f0ad2aa
GRUB has special code for handling an http header that is split
f0ad2aa
across two packets.
f0ad2aa
f0ad2aa
The code tracks the end of line by looking for a "\n" byte. The
f0ad2aa
code for split headers has always advanced the pointer just past the
f0ad2aa
end of the line, whereas the code that handles unsplit headers does
f0ad2aa
not advance the pointer. This extra advance causes the length to be
f0ad2aa
one greater, which breaks an assumption in parse_line(), leading to
f0ad2aa
it writing a NUL byte one byte past the end of the buffer where we
f0ad2aa
reconstruct the line from the two packets.
f0ad2aa
f0ad2aa
It's conceivable that an attacker controlled set of packets could
f0ad2aa
cause this to zero out the first byte of the "next" pointer of the
f0ad2aa
grub_mm_region structure following the current_line buffer.
f0ad2aa
f0ad2aa
Do not advance the pointer in the split header case.
f0ad2aa
f0ad2aa
Fixes: CVE-2022-28734
f0ad2aa
f0ad2aa
Signed-off-by: Daniel Axtens <dja@axtens.net>
f0ad2aa
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
f0ad2aa
(cherry picked from commit e9fb459638811c12b0989dbf64e3e124974ef617)
f0ad2aa
---
f0ad2aa
 grub-core/net/http.c | 4 +---
f0ad2aa
 1 file changed, 1 insertion(+), 3 deletions(-)
f0ad2aa
f0ad2aa
diff --git a/grub-core/net/http.c b/grub-core/net/http.c
f0ad2aa
index 19cb8768e3..58546739a2 100644
f0ad2aa
--- a/grub-core/net/http.c
f0ad2aa
+++ b/grub-core/net/http.c
f0ad2aa
@@ -193,9 +193,7 @@ http_receive (grub_net_tcp_socket_t sock __attribute__ ((unused)),
f0ad2aa
 	  int have_line = 1;
f0ad2aa
 	  char *t;
f0ad2aa
 	  ptr = grub_memchr (nb->data, '\n', nb->tail - nb->data);
f0ad2aa
-	  if (ptr)
f0ad2aa
-	    ptr++;
f0ad2aa
-	  else
f0ad2aa
+	  if (ptr == NULL)
f0ad2aa
 	    {
f0ad2aa
 	      have_line = 0;
f0ad2aa
 	      ptr = (char *) nb->tail;