Blame SOURCES/0231-net-netbuff-Block-overly-large-netbuff-allocs.patch

fd0330
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
fd0330
From: Daniel Axtens <dja@axtens.net>
fd0330
Date: Tue, 8 Mar 2022 23:47:46 +1100
fd0330
Subject: [PATCH] net/netbuff: Block overly large netbuff allocs
fd0330
fd0330
A netbuff shouldn't be too huge. It's bounded by MTU and TCP segment
fd0330
reassembly.
fd0330
fd0330
This helps avoid some bugs (and provides a spot to instrument to catch
fd0330
them at their source).
fd0330
fd0330
Signed-off-by: Daniel Axtens <dja@axtens.net>
fd0330
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
fd0330
(cherry picked from commit ee9591103004cd13b4efadda671536090ca7fd57)
fd0330
---
fd0330
 grub-core/net/netbuff.c | 13 +++++++++++++
fd0330
 1 file changed, 13 insertions(+)
fd0330
fd0330
diff --git a/grub-core/net/netbuff.c b/grub-core/net/netbuff.c
fd0330
index dbeeefe478..d5e9e9a0d7 100644
fd0330
--- a/grub-core/net/netbuff.c
fd0330
+++ b/grub-core/net/netbuff.c
fd0330
@@ -79,10 +79,23 @@ grub_netbuff_alloc (grub_size_t len)
fd0330
 
fd0330
   COMPILE_TIME_ASSERT (NETBUFF_ALIGN % sizeof (grub_properly_aligned_t) == 0);
fd0330
 
fd0330
+  /*
fd0330
+   * The largest size of a TCP packet is 64 KiB, and everything else
fd0330
+   * should be a lot smaller - most MTUs are 1500 or less. Cap data
fd0330
+   * size at 64 KiB + a buffer.
fd0330
+   */
fd0330
+  if (len > 0xffffUL + 0x1000UL)
fd0330
+    {
fd0330
+      grub_error (GRUB_ERR_BUG,
fd0330
+                  "attempted to allocate a packet that is too big");
fd0330
+      return NULL;
fd0330
+    }
fd0330
+
fd0330
   if (len < NETBUFFMINLEN)
fd0330
     len = NETBUFFMINLEN;
fd0330
 
fd0330
   len = ALIGN_UP (len, NETBUFF_ALIGN);
fd0330
+
fd0330
 #ifdef GRUB_MACHINE_EMU
fd0330
   data = grub_malloc (len + sizeof (*nb));
fd0330
 #else