Blame SOURCES/0258-net-http-Fix-OOB-write-for-split-http-headers.patch

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