Open
net/ethernet: 校验报文长度后再解析 Ethernet/VLAN/LLC/SNAP 头 #647
huijing_zhangAdd on 3 days ago
net/ethernet: 校验报文长度后再解析 Ethernet/VLAN/LLC/SNAP 头 #647
Open
Total: 3 files changed+84-1
| @@ -0,0 +1,77 @@ | |||
| 1 | +From ed69a06504ecf07cf68732e3571a60d28a1ff365 Mon Sep 17 00:00:00 2001 | ||
| 2 | +From: Avnish Chouhan <avnish@linux.ibm.com> | ||
| 3 | +Date: Tue, 13 Oct 2026 18:43:20 +0530 | ||
| 4 | +Subject: [PATCH] net/ethernet: Validate packet length before parsing | ||
| 5 | + Ethernet/VLAN/LLC/SNAP headers | ||
| 6 | + | ||
| 7 | +Add bounds checks before accessing the Ethernet, VLAN, LLC and SNAP | ||
| 8 | +headers of received frames. Truncated or crafted packets could | ||
| 9 | +otherwise cause reads beyond the received packet length while parsing. | ||
| 10 | + | ||
| 11 | +Signed-off-by: Avnish Chouhan <avnish@linux.ibm.com> | ||
| 12 | +Reviewed-by: Leo Sandoval <lsandova@redhat.com> | ||
| 13 | +Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com> | ||
| 14 | +Part-of: <https://gitlab.freedesktop.org/gnu-grub/grub/-/merge_requests/309> | ||
| 15 | +Reference:https://gitlab.freedesktop.org/gnu-grub/grub/-/commit/ed69a06504ecf07cf68732e3571a60d28a1ff365 | ||
| 16 | +--- | ||
| 17 | + grub-core/net/ethernet.c | 24 ++++++++++++++++++++++++ | ||
| 18 | + 1 file changed, 24 insertions(+) | ||
| 19 | + | ||
| 20 | +diff --git a/grub-core/net/ethernet.c b/grub-core/net/ethernet.c | ||
| 21 | +index 955817e13..a3d7a3b2c 100644 | ||
| 22 | +--- a/grub-core/net/ethernet.c | ||
| 23 | ++++ b/grub-core/net/ethernet.c | ||
| 24 | +@@ -114,12 +114,24 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb, | ||
| 25 | + grub_uint8_t etherhdr_size = sizeof (*eth); | ||
| 26 | + grub_uint16_t vlantag = 0; | ||
| 27 | + | ||
| 28 | ++ /* Drop packet if too short to hold the base Ethernet header. */ | ||
| 29 | ++ if (nb->tail - nb->data < (grub_ssize_t) sizeof (*eth)) | ||
| 30 | ++ { | ||
| 31 | ++ grub_netbuff_free (nb); | ||
| 32 | ++ return GRUB_ERR_NONE; | ||
| 33 | ++ } | ||
| 34 | + | ||
| 35 | + /* Check if a vlan-tag is present. If so, the ethernet header is 4 bytes */ | ||
| 36 | + /* longer than the original one. The vlantag id is extracted and the header */ | ||
| 37 | + /* is reseted to the original size. */ | ||
| 38 | + if (grub_get_unaligned16 (nb->data + etherhdr_size - 2) == grub_cpu_to_be16_compile_time (VLANTAG_IDENTIFIER)) | ||
| 39 | + { | ||
| 40 | ++ /* Drop packet if too short to hold the 4-byte VLAN extension. */ | ||
| 41 | ++ if (nb->tail - nb->data < etherhdr_size + 4) | ||
| 42 | ++ { | ||
| 43 | ++ grub_netbuff_free (nb); | ||
| 44 | ++ return GRUB_ERR_NONE; | ||
| 45 | ++ } | ||
| 46 | + vlantag = grub_be_to_cpu16 (grub_get_unaligned16 (nb->data + etherhdr_size)); | ||
| 47 | + etherhdr_size += 4; | ||
| 48 | + /* Move eth type to the original position */ | ||
| 49 | +@@ -135,6 +147,12 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb, | ||
| 50 | + | ||
| 51 | + if (type <= 1500) | ||
| 52 | + { | ||
| 53 | ++ /* Drop packet if too short to hold the LLC header. */ | ||
| 54 | ++ if (nb->tail - nb->data < (grub_ssize_t) sizeof (*llch)) | ||
| 55 | ++ { | ||
| 56 | ++ grub_netbuff_free (nb); | ||
| 57 | ++ return GRUB_ERR_NONE; | ||
| 58 | ++ } | ||
| 59 | + llch = (struct llchdr *) nb->data; | ||
| 60 | + type = llch->dsap & LLCADDRMASK; | ||
| 61 | + | ||
| 62 | +@@ -143,6 +161,12 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb, | ||
| 63 | + err = grub_netbuff_pull (nb, sizeof (*llch)); | ||
| 64 | + if (err) | ||
| 65 | + return err; | ||
| 66 | ++ /* Drop packet if too short to hold the SNAP header. */ | ||
| 67 | ++ if (nb->tail - nb->data < (grub_ssize_t) sizeof (*snaph)) | ||
| 68 | ++ { | ||
| 69 | ++ grub_netbuff_free (nb); | ||
| 70 | ++ return GRUB_ERR_NONE; | ||
| 71 | ++ } | ||
| 72 | + snaph = (struct snaphdr *) nb->data; | ||
| 73 | + type = snaph->type; | ||
| 74 | + } | ||
| 75 | +-- | ||
| 76 | +GitLab | ||
| 77 | + | ||
| @@ -395,3 +395,4 @@ Patch398: backport-nx-18-efi-use-EFI_LOADER_-CODE-DATA-for-kernel-and-init | |||
| 395 | Patch399: backport-nx-19-x86-efi-Fix-an-incorrect-array-size-in-kernel-alloca.patch | 395 | Patch399: backport-nx-19-x86-efi-Fix-an-incorrect-array-size-in-kernel-alloca.patch |
| 396 | Patch400: backport-grub_dl_load_segments-page-align-the-tramp-GOT-areas.patch | 396 | Patch400: backport-grub_dl_load_segments-page-align-the-tramp-GOT-areas.patch |
| 397 | Patch401: 0001-efi-fix-riscv64-grub_efi_check_nx_image_support-in-l.patch | 397 | Patch401: 0001-efi-fix-riscv64-grub_efi_check_nx_image_support-in-l.patch |
| 398 | +Patch402: backport-net-ethernet-validate-packet-header-lengths.patch | ||
| @@ -32,7 +32,7 @@ | |||
| 32 | Name: grub2 | 32 | Name: grub2 |
| 33 | Epoch: 1 | 33 | Epoch: 1 |
| 34 | Version: 2.12 | 34 | Version: 2.12 |
| 35 | -Release: 57 | 35 | +Release: 58 |
| 36 | Summary: Bootloader with support for Linux, Multiboot and more | 36 | Summary: Bootloader with support for Linux, Multiboot and more |
| 37 | License: GPLv3+ | 37 | License: GPLv3+ |
| 38 | URL: http://www.gnu.org/software/grub/ | 38 | URL: http://www.gnu.org/software/grub/ |
| @@ -501,6 +501,11 @@ fi | |||
| 501 | %{_datadir}/man/man* | 501 | %{_datadir}/man/man* |
| 502 | 502 | ||
| 503 | %changelog | 503 | %changelog |
| 504 | +* Mon Nov 16 2026 huijing_zhang <zhanghuijing@kylinos.cn> - 1:2.12-58 | ||
| 505 | +- Type:bugfix | ||
| 506 | +- CVE:NA | ||
| 507 | +- SUG:NA | ||
| 508 | +- DESC: net/ethernet: validate packet length before parsing Ethernet/VLAN/LLC/SNAP headers (fix issue #200) | ||
| 504 | * Mon Oct 12 2026 ouuleilei <wangliu@iscas.ac.cn> - 1:2.12-57 | 509 | * Mon Oct 12 2026 ouuleilei <wangliu@iscas.ac.cn> - 1:2.12-57 |
| 505 | - Type:bugfix | 510 | - Type:bugfix |
| 506 | - CVE:NA | 511 | - CVE:NA |
每条changelog之间需要加一个空行作分隔 @huijing_zhang