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

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