d102a4
From 31aaf902aa6ba31ab8f41543b2d4da8c01f3b861 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:34:30 +0400
d102a4
Subject: [PATCH 5/7] tftp: check tftp_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-3595
d102a4
Fixes: https://gitlab.freedesktop.org/slirp/libslirp/-/issues/46
d102a4
d102a4
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
d102a4
(cherry picked from commit 3f17948137155f025f7809fdc38576d5d2451c3d)
d102a4
---
d102a4
 src/tftp.c | 6 +++++-
d102a4
 1 file changed, 5 insertions(+), 1 deletion(-)
d102a4
d102a4
diff --git a/src/tftp.c b/src/tftp.c
d102a4
index c6950ee..e06911d 100644
d102a4
--- a/src/tftp.c
d102a4
+++ b/src/tftp.c
d102a4
@@ -446,7 +446,11 @@ static void tftp_handle_error(Slirp *slirp, struct sockaddr_storage *srcsas,
d102a4
 
d102a4
 void tftp_input(struct sockaddr_storage *srcsas, struct mbuf *m)
d102a4
 {
d102a4
-    struct tftp_t *tp = (struct tftp_t *)m->m_data;
d102a4
+    struct tftp_t *tp = mtod_check(m, offsetof(struct tftp_t, x.tp_buf));
d102a4
+
d102a4
+    if (tp == NULL) {
d102a4
+        return;
d102a4
+    }
d102a4
 
d102a4
     switch (ntohs(tp->tp_op)) {
d102a4
     case TFTP_RRQ:
d102a4
-- 
d102a4
2.29.0
d102a4