cd7acf
From ca41f7eaa58d3f63a3df58d812b3cec32343ab6a Mon Sep 17 00:00:00 2001
cd7acf
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
cd7acf
Date: Fri, 4 Jun 2021 16:40:23 +0400
cd7acf
Subject: [PATCH 7/7] udp: check upd_input buffer size
cd7acf
MIME-Version: 1.0
cd7acf
Content-Type: text/plain; charset=UTF-8
cd7acf
Content-Transfer-Encoding: 8bit
cd7acf
cd7acf
Fixes: CVE-2021-3594
cd7acf
Fixes: https://gitlab.freedesktop.org/slirp/libslirp/-/issues/47
cd7acf
cd7acf
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
cd7acf
(cherry picked from commit 74572be49247c8c5feae7c6e0b50c4f569ca9824)
cd7acf
---
cd7acf
 src/udp.c | 5 ++++-
cd7acf
 1 file changed, 4 insertions(+), 1 deletion(-)
cd7acf
cd7acf
diff --git a/src/udp.c b/src/udp.c
cd7acf
index 050cee4..e4578aa 100644
cd7acf
--- a/src/udp.c
cd7acf
+++ b/src/udp.c
cd7acf
@@ -94,7 +94,10 @@ void udp_input(register struct mbuf *m, int iphlen)
cd7acf
     /*
cd7acf
      * Get IP and UDP header together in first mbuf.
cd7acf
      */
cd7acf
-    ip = mtod(m, struct ip *);
cd7acf
+    ip = mtod_check(m, iphlen + sizeof(struct udphdr));
cd7acf
+    if (ip == NULL) {
cd7acf
+        goto bad;
cd7acf
+    }
cd7acf
     uh = (struct udphdr *)((char *)ip + iphlen);
cd7acf
 
cd7acf
     /*
cd7acf
-- 
cd7acf
2.29.0
cd7acf