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