0015-net-http-Error-out-on-headers-with-LF-without-CR.patch 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. From 2974684d2f7f85a5c57af8155cc3b70c04ec1d6b Mon Sep 17 00:00:00 2001
  2. From: Daniel Axtens <dja@axtens.net>
  3. Date: Tue, 8 Mar 2022 19:04:40 +1100
  4. Subject: [PATCH] net/http: Error out on headers with LF without CR
  5. In a similar vein to the previous patch, parse_line() would write
  6. a NUL byte past the end of the buffer if there was an HTTP header
  7. with a LF rather than a CRLF.
  8. RFC-2616 says:
  9. Many HTTP/1.1 header field values consist of words separated by LWS
  10. or special characters. These special characters MUST be in a quoted
  11. string to be used within a parameter value (as defined in section 3.6).
  12. We don't support quoted sections or continuation lines, etc.
  13. If we see an LF that's not part of a CRLF, bail out.
  14. Fixes: CVE-2022-28734
  15. Signed-off-by: Daniel Axtens <dja@axtens.net>
  16. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  17. Upstream: b26b4c08e7119281ff30d0fb4a6169bd2afa8fe4
  18. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  19. ---
  20. grub-core/net/http.c | 8 ++++++++
  21. 1 file changed, 8 insertions(+)
  22. diff --git a/grub-core/net/http.c b/grub-core/net/http.c
  23. index a19b0a205..1fa62b5cb 100644
  24. --- a/grub-core/net/http.c
  25. +++ b/grub-core/net/http.c
  26. @@ -68,7 +68,15 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len)
  27. char *end = ptr + len;
  28. while (end > ptr && *(end - 1) == '\r')
  29. end--;
  30. +
  31. + /* LF without CR. */
  32. + if (end == ptr + len)
  33. + {
  34. + data->errmsg = grub_strdup (_("invalid HTTP header - LF without CR"));
  35. + return GRUB_ERR_NONE;
  36. + }
  37. *end = 0;
  38. +
  39. /* Trailing CRLF. */
  40. if (data->in_chunk_len == 1)
  41. {
  42. --
  43. 2.41.0