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