nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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