nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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