git: f96603b56f0f - main - tcp, udp: Permit binding with AF_UNSPEC if the address is INADDR_ANY
Mark Johnston
markj at FreeBSD.org
Mon May 31 23:09:51 UTC 2021
The branch main has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=f96603b56f0f74fa52d8f1ef0be869fca7305b99
commit f96603b56f0f74fa52d8f1ef0be869fca7305b99
Author: Mark Johnston <markj at FreeBSD.org>
AuthorDate: 2021-05-31 22:53:34 +0000
Commit: Mark Johnston <markj at FreeBSD.org>
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 <bakul at iitbombay.org>
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);
More information about the dev-commits-src-main
mailing list