nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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