From owner-svn-src-head@freebsd.org Mon May 22 15:29:12 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5D57AD78215; Mon, 22 May 2017 15:29:12 +0000 (UTC) (envelope-from tuexen@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 150081F8E; Mon, 22 May 2017 15:29:12 +0000 (UTC) (envelope-from tuexen@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v4MFTBbv066797; Mon, 22 May 2017 15:29:11 GMT (envelope-from tuexen@FreeBSD.org) Received: (from tuexen@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v4MFTAm2066795; Mon, 22 May 2017 15:29:10 GMT (envelope-from tuexen@FreeBSD.org) Message-Id: <201705221529.v4MFTAm2066795@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: tuexen set sender to tuexen@FreeBSD.org using -f From: Michael Tuexen Date: Mon, 22 May 2017 15:29:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r318649 - in head/sys: netinet netinet6 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 May 2017 15:29:12 -0000 Author: tuexen Date: Mon May 22 15:29:10 2017 New Revision: 318649 URL: https://svnweb.freebsd.org/changeset/base/318649 Log: 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 MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D9163 Modified: head/sys/netinet/tcp_usrreq.c head/sys/netinet6/udp6_usrreq.c Modified: head/sys/netinet/tcp_usrreq.c ============================================================================== --- head/sys/netinet/tcp_usrreq.c Mon May 22 15:12:49 2017 (r318648) +++ head/sys/netinet/tcp_usrreq.c Mon May 22 15:29:10 2017 (r318649) @@ -597,6 +597,10 @@ tcp6_usr_connect(struct socket *so, stru 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, stru #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; Modified: head/sys/netinet6/udp6_usrreq.c ============================================================================== --- head/sys/netinet6/udp6_usrreq.c Mon May 22 15:12:49 2017 (r318648) +++ head/sys/netinet6/udp6_usrreq.c Mon May 22 15:29:10 2017 (r318649) @@ -1119,6 +1119,10 @@ udp6_connect(struct socket *so, struct s 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; @@ -1136,6 +1140,11 @@ udp6_connect(struct socket *so, struct s 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)) {