nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0520-net-ip-Do-IP-fragment-maths-safely.patch

bf0270
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
bf0270
From: Daniel Axtens <dja@axtens.net>
bf0270
Date: Mon, 20 Dec 2021 19:41:21 +1100
bf0270
Subject: [PATCH] net/ip: Do IP fragment maths safely
bf0270
bf0270
This avoids an underflow and subsequent unpleasantness.
bf0270
bf0270
Fixes: CVE-2022-28733
bf0270
bf0270
Signed-off-by: Daniel Axtens <dja@axtens.net>
bf0270
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
bf0270
(cherry picked from commit eb74e5743ca7e18a5e75c392fe0b21d1549a1936)
bf0270
(cherry picked from commit 552ad34583e788542e9ca08524a0d4bc8f98c297)
bf0270
(cherry picked from commit 2c8cb7e3b8b48b136a950e5692fa6251b76df90e)
bf0270
(cherry picked from commit 17bb2fe79e6b9688cf2008b840af9022804204ec)
bf0270
---
bf0270
 grub-core/net/ip.c | 10 +++++++++-
bf0270
 1 file changed, 9 insertions(+), 1 deletion(-)
bf0270
bf0270
diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c
bf0270
index 9a4e589aa3..c766ac65f5 100644
bf0270
--- a/grub-core/net/ip.c
bf0270
+++ b/grub-core/net/ip.c
bf0270
@@ -25,6 +25,7 @@
bf0270
 #include <grub/net/netbuff.h>
bf0270
 #include <grub/mm.h>
bf0270
 #include <grub/priority_queue.h>
bf0270
+#include <grub/safemath.h>
bf0270
 #include <grub/time.h>
bf0270
 
bf0270
 struct iphdr {
bf0270
@@ -552,7 +553,14 @@ grub_net_recv_ip4_packets (struct grub_net_buff *nb,
bf0270
     {
bf0270
       rsm->total_len = (8 * (grub_be_to_cpu16 (iph->frags) & OFFSET_MASK)
bf0270
 			+ (nb->tail - nb->data));
bf0270
-      rsm->total_len -= ((iph->verhdrlen & 0xf) * sizeof (grub_uint32_t));
bf0270
+
bf0270
+      if (grub_sub (rsm->total_len, (iph->verhdrlen & 0xf) * sizeof (grub_uint32_t),
bf0270
+		    &rsm->total_len))
bf0270
+	{
bf0270
+	  grub_dprintf ("net", "IP reassembly size underflow\n");
bf0270
+	  return GRUB_ERR_NONE;
bf0270
+	}
bf0270
+
bf0270
       rsm->asm_netbuff = grub_netbuff_alloc (rsm->total_len);
bf0270
       if (!rsm->asm_netbuff)
bf0270
 	{