nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0533-net-http-Error-out-on-headers-with-LF-without-CR.patch

0ccc47
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
0ccc47
From: Daniel Axtens <dja@axtens.net>
0ccc47
Date: Tue, 8 Mar 2022 19:04:40 +1100
0ccc47
Subject: [PATCH] net/http: Error out on headers with LF without CR
0ccc47
0ccc47
In a similar vein to the previous patch, parse_line() would write
0ccc47
a NUL byte past the end of the buffer if there was an HTTP header
0ccc47
with a LF rather than a CRLF.
0ccc47
0ccc47
RFC-2616 says:
0ccc47
0ccc47
  Many HTTP/1.1 header field values consist of words separated by LWS
0ccc47
  or special characters. These special characters MUST be in a quoted
0ccc47
  string to be used within a parameter value (as defined in section 3.6).
0ccc47
0ccc47
We don't support quoted sections or continuation lines, etc.
0ccc47
0ccc47
If we see an LF that's not part of a CRLF, bail out.
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 d232ad41ac4979a9de4d746e5fdff9caf0e303de)
0ccc47
(cherry picked from commit 8960e6d6137090a7e8c6592077da6e387a4ef972)
0ccc47
(cherry picked from commit 9b6b9398c90dd76ce0b935d21c4ecb8954c4b2b7)
0ccc47
---
0ccc47
 grub-core/net/http.c | 8 ++++++++
0ccc47
 1 file changed, 8 insertions(+)
0ccc47
0ccc47
diff --git a/grub-core/net/http.c b/grub-core/net/http.c
0ccc47
index 7fa2dcaea7..745f429b51 100644
0ccc47
--- a/grub-core/net/http.c
0ccc47
+++ b/grub-core/net/http.c
0ccc47
@@ -69,7 +69,15 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len)
0ccc47
   char *end = ptr + len;
0ccc47
   while (end > ptr && *(end - 1) == '\r')
0ccc47
     end--;
0ccc47
+
0ccc47
+  /* LF without CR. */
0ccc47
+  if (end == ptr + len)
0ccc47
+    {
0ccc47
+      data->errmsg = grub_strdup (_("invalid HTTP header - LF without CR"));
0ccc47
+      return GRUB_ERR_NONE;
0ccc47
+    }
0ccc47
   *end = 0;
0ccc47
+
0ccc47
   /* Trailing CRLF.  */
0ccc47
   if (data->in_chunk_len == 1)
0ccc47
     {