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

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