nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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