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

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