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