blob: 54252d6bc7706397e3defcf68307ddef6dc89f92 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
From 4e355804d57d5686defc363c70f81e6f58cd08f0 Mon Sep 17 00:00:00 2001
From: Simon Josefsson <simon@josefsson.org>
Date: Fri, 17 Dec 2021 21:52:18 -0800
Subject: [PATCH] ftp: check that PASV/LSPV addresses match.
* NEWS: Mention change.
* ftp/ftp.c (initconn): Validate returned addresses.
CVE: CVE-2021-40491
Upstream-Status: Backport
[https://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=58cb043b190fd04effdaea7c9403416b436e50dd]
Signed-off-by: Minjae Kim <flowergom@gmail.com>
---
ftp/ftp.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/ftp/ftp.c b/ftp/ftp.c
index 9813586..7c72cb2 100644
--- a/ftp/ftp.c
+++ b/ftp/ftp.c
@@ -1344,6 +1344,13 @@ initconn (void)
uint32_t *pu32 = (uint32_t *) &data_addr_sa4->sin_addr.s_addr;
pu32[0] = htonl ( (h[0] << 24) | (h[1] << 16) | (h[2] << 8) | h[3]);
}
+ if (data_addr_sa4->sin_addr.s_addr
+ != ((struct sockaddr_in *) &hisctladdr)->sin_addr.s_addr)
+ {
+ printf ("Passive mode address mismatch.\n");
+ (void) command ("ABOR"); /* Cancel any open connection. */
+ goto bad;
+ }
} /* LPSV IPv4 */
else /* IPv6 */
{
@@ -1374,6 +1381,13 @@ initconn (void)
pu32[2] = htonl ( (h[8] << 24) | (h[9] << 16) | (h[10] << 8) | h[11]);
pu32[3] = htonl ( (h[12] << 24) | (h[13] << 16) | (h[14] << 8) | h[15]);
}
+ if (data_addr_sa6->sin6_addr.s6_addr
+ != ((struct sockaddr_in6 *) &hisctladdr)->sin6_addr.s6_addr)
+ {
+ printf ("Passive mode address mismatch.\n");
+ (void) command ("ABOR"); /* Cancel any open connection. */
+ goto bad;
+ }
} /* LPSV IPv6 */
}
else /* !EPSV && !LPSV */
@@ -1394,6 +1408,13 @@ initconn (void)
| ((a2 & 0xff) << 8) | (a3 & 0xff) );
data_addr_sa4->sin_port =
htons (((p0 & 0xff) << 8) | (p1 & 0xff));
+ if (data_addr_sa4->sin_addr.s_addr
+ != ((struct sockaddr_in *) &hisctladdr)->sin_addr.s_addr)
+ {
+ printf ("Passive mode address mismatch.\n");
+ (void) command ("ABOR"); /* Cancel any open connection. */
+ goto bad;
+ }
} /* PASV */
else
{
--
2.25.1
|