nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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