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

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