Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 1 | From ec6bfd3237394c1c7dbf2fd73417173318d22f4b Mon Sep 17 00:00:00 2001 |
| 2 | From: Daniel Axtens <dja@axtens.net> |
| 3 | Date: Tue, 8 Mar 2022 18:17:03 +1100 |
| 4 | Subject: [PATCH] net/http: Fix OOB write for split http headers |
| 5 | |
| 6 | GRUB has special code for handling an http header that is split |
| 7 | across two packets. |
| 8 | |
| 9 | The code tracks the end of line by looking for a "\n" byte. The |
| 10 | code for split headers has always advanced the pointer just past the |
| 11 | end of the line, whereas the code that handles unsplit headers does |
| 12 | not advance the pointer. This extra advance causes the length to be |
| 13 | one greater, which breaks an assumption in parse_line(), leading to |
| 14 | it writing a NUL byte one byte past the end of the buffer where we |
| 15 | reconstruct the line from the two packets. |
| 16 | |
| 17 | It's conceivable that an attacker controlled set of packets could |
| 18 | cause this to zero out the first byte of the "next" pointer of the |
| 19 | grub_mm_region structure following the current_line buffer. |
| 20 | |
| 21 | Do not advance the pointer in the split header case. |
| 22 | |
| 23 | Fixes: CVE-2022-28734 |
| 24 | |
| 25 | Signed-off-by: Daniel Axtens <dja@axtens.net> |
| 26 | Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> |
| 27 | |
| 28 | Upstream-Status: Backport |
| 29 | CVE: CVE-2022-28734 |
| 30 | |
| 31 | Reference to upstream patch: |
| 32 | https://git.savannah.gnu.org/cgit/grub.git/commit/?id=ec6bfd3237394c1c7dbf2fd73417173318d22f4b |
| 33 | |
| 34 | Signed-off-by: Yongxin Liu <yongxin.liu@windriver.com> |
| 35 | --- |
| 36 | grub-core/net/http.c | 4 +--- |
| 37 | 1 file changed, 1 insertion(+), 3 deletions(-) |
| 38 | |
| 39 | diff --git a/grub-core/net/http.c b/grub-core/net/http.c |
| 40 | index f8d7bf0cd..33a0a28c4 100644 |
| 41 | --- a/grub-core/net/http.c |
| 42 | +++ b/grub-core/net/http.c |
| 43 | @@ -190,9 +190,7 @@ http_receive (grub_net_tcp_socket_t sock __attribute__ ((unused)), |
| 44 | int have_line = 1; |
| 45 | char *t; |
| 46 | ptr = grub_memchr (nb->data, '\n', nb->tail - nb->data); |
| 47 | - if (ptr) |
| 48 | - ptr++; |
| 49 | - else |
| 50 | + if (ptr == NULL) |
| 51 | { |
| 52 | have_line = 0; |
| 53 | ptr = (char *) nb->tail; |
| 54 | -- |
| 55 | 2.34.1 |
| 56 | |