03fb49
From 31aaf902aa6ba31ab8f41543b2d4da8c01f3b861 Mon Sep 17 00:00:00 2001
03fb49
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
03fb49
Date: Fri, 4 Jun 2021 16:34:30 +0400
03fb49
Subject: [PATCH 5/7] tftp: check tftp_input buffer size
03fb49
MIME-Version: 1.0
03fb49
Content-Type: text/plain; charset=UTF-8
03fb49
Content-Transfer-Encoding: 8bit
03fb49
03fb49
Fixes: CVE-2021-3595
03fb49
Fixes: https://gitlab.freedesktop.org/slirp/libslirp/-/issues/46
03fb49
03fb49
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
03fb49
(cherry picked from commit 3f17948137155f025f7809fdc38576d5d2451c3d)
03fb49
---
03fb49
 src/tftp.c | 6 +++++-
03fb49
 1 file changed, 5 insertions(+), 1 deletion(-)
03fb49
03fb49
diff --git a/src/tftp.c b/src/tftp.c
03fb49
index c6950ee..e06911d 100644
03fb49
--- a/src/tftp.c
03fb49
+++ b/src/tftp.c
03fb49
@@ -446,7 +446,11 @@ static void tftp_handle_error(Slirp *slirp, struct sockaddr_storage *srcsas,
03fb49
 
03fb49
 void tftp_input(struct sockaddr_storage *srcsas, struct mbuf *m)
03fb49
 {
03fb49
-    struct tftp_t *tp = (struct tftp_t *)m->m_data;
03fb49
+    struct tftp_t *tp = mtod_check(m, offsetof(struct tftp_t, x.tp_buf));
03fb49
+
03fb49
+    if (tp == NULL) {
03fb49
+        return;
03fb49
+    }
03fb49
 
03fb49
     switch (ntohs(tp->tp_op)) {
03fb49
     case TFTP_RRQ:
03fb49
-- 
03fb49
2.29.0
03fb49