nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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