From owner-dev-commits-src-all@freebsd.org Mon May 31 23:09:51 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1F3406329A1; Mon, 31 May 2021 23:09:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Fv9wt6498z3PXP; Mon, 31 May 2021 23:09:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 918EE18BCA; Mon, 31 May 2021 23:09:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 14VN9oxd040190; Mon, 31 May 2021 23:09:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 14VN9oR5040189; Mon, 31 May 2021 23:09:50 GMT (envelope-from git) Date: Mon, 31 May 2021 23:09:50 GMT Message-Id: <202105312309.14VN9oR5040189@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: f96603b56f0f - main - tcp, udp: Permit binding with AF_UNSPEC if the address is INADDR_ANY MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f96603b56f0f74fa52d8f1ef0be869fca7305b99 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 May 2021 23:09:51 -0000 The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=f96603b56f0f74fa52d8f1ef0be869fca7305b99 commit f96603b56f0f74fa52d8f1ef0be869fca7305b99 Author: Mark Johnston AuthorDate: 2021-05-31 22:53:34 +0000 Commit: Mark Johnston CommitDate: 2021-05-31 22:53:34 +0000 tcp, udp: Permit binding with AF_UNSPEC if the address is INADDR_ANY Prior to commit f161d294b we only checked the sockaddr length, but now we verify the address family as well. This breaks at least ttcp. Relax the check to avoid breaking compatibility too much: permit AF_UNSPEC if the address is INADDR_ANY. Fixes: f161d294b Reported by: Bakul Shah Reviewed by: tuexen MFC after: 3 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D30539 --- sys/netinet/tcp_usrreq.c | 11 +++++++++-- sys/netinet/udp_usrreq.c | 13 +++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index caef798772ea..7f1b698408e5 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -321,8 +321,15 @@ tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td) struct sockaddr_in *sinp; sinp = (struct sockaddr_in *)nam; - if (nam->sa_family != AF_INET) - return (EAFNOSUPPORT); + if (nam->sa_family != AF_INET) { + /* + * Preserve compatibility with old programs. + */ + if (nam->sa_family != AF_UNSPEC || + sinp->sin_addr.s_addr != INADDR_ANY) + return (EAFNOSUPPORT); + nam->sa_family = AF_INET; + } if (nam->sa_len != sizeof(*sinp)) return (EINVAL); diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 62a07701df6c..5c9dbd36a1d6 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1622,14 +1622,23 @@ udp_bind(struct socket *so, struct sockaddr *nam, struct thread *td) { struct inpcb *inp; struct inpcbinfo *pcbinfo; + struct sockaddr_in *sinp; int error; pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol); inp = sotoinpcb(so); KASSERT(inp != NULL, ("udp_bind: inp == NULL")); - if (nam->sa_family != AF_INET) - return (EAFNOSUPPORT); + sinp = (struct sockaddr_in *)nam; + if (nam->sa_family != AF_INET) { + /* + * Preserve compatibility with old programs. + */ + if (nam->sa_family != AF_UNSPEC || + sinp->sin_addr.s_addr != INADDR_ANY) + return (EAFNOSUPPORT); + nam->sa_family = AF_INET; + } if (nam->sa_len != sizeof(struct sockaddr_in)) return (EINVAL);