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

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