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