summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortuexen <tuexen@FreeBSD.org>2017-06-01 10:03:41 +0000
committertuexen <tuexen@FreeBSD.org>2017-06-01 10:03:41 +0000
commitc5ed50cbb819bcac3a2b8deb80c7b5ad14b32746 (patch)
tree017ed1ac05a9ddc218e23d3896d820d3f7bb6607
parentf8f15c3dc0453ea0ed276dcc50c61a9d79cde955 (diff)
downloadFreeBSD-src-c5ed50cbb819bcac3a2b8deb80c7b5ad14b32746.zip
FreeBSD-src-c5ed50cbb819bcac3a2b8deb80c7b5ad14b32746.tar.gz
MFC r318649:
The connect() system call should return -1 and set errno to EAFNOSUPPORT if it is called on a TCP socket * with an IPv6 address and the socket is bound to an IPv4-mapped IPv6 address. * with an IPv4-mapped IPv6 address and the socket is bound to an IPv6 address. Thanks to Jonathan T. Leighton for reporting this issue. Reviewed by: bz, gnn Differential Revision: https://reviews.freebsd.org/D9163
-rw-r--r--sys/netinet/tcp_usrreq.c9
-rw-r--r--sys/netinet6/udp6_usrreq.c9
2 files changed, 18 insertions, 0 deletions
diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c
index 9a53b93..6a7bf00 100644
--- a/sys/netinet/tcp_usrreq.c
+++ b/sys/netinet/tcp_usrreq.c
@@ -597,6 +597,10 @@ tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
error = EINVAL;
goto out;
}
+ if ((inp->inp_vflag & INP_IPV4) == 0) {
+ error = EAFNOSUPPORT;
+ goto out;
+ }
in6_sin6_2_sin(&sin, sin6p);
inp->inp_vflag |= INP_IPV4;
@@ -614,6 +618,11 @@ tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
#endif
error = tp->t_fb->tfb_tcp_output(tp);
goto out;
+ } else {
+ if ((inp->inp_vflag & INP_IPV6) == 0) {
+ error = EAFNOSUPPORT;
+ goto out;
+ }
}
#endif
inp->inp_vflag &= ~INP_IPV4;
diff --git a/sys/netinet6/udp6_usrreq.c b/sys/netinet6/udp6_usrreq.c
index cc10527..56faf5a 100644
--- a/sys/netinet6/udp6_usrreq.c
+++ b/sys/netinet6/udp6_usrreq.c
@@ -1104,6 +1104,10 @@ udp6_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
error = EINVAL;
goto out;
}
+ if ((inp->inp_vflag & INP_IPV4) == 0) {
+ error = EAFNOSUPPORT;
+ goto out;
+ }
if (inp->inp_faddr.s_addr != INADDR_ANY) {
error = EISCONN;
goto out;
@@ -1121,6 +1125,11 @@ udp6_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
if (error == 0)
soisconnected(so);
goto out;
+ } else {
+ if ((inp->inp_vflag & INP_IPV6) == 0) {
+ error = EAFNOSUPPORT;
+ goto out;
+ }
}
#endif
if (!IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) {
OpenPOWER on IntegriCloud