Skip to content

Commit 29c486d

Browse files
Eric Dumazetdavem330
authored andcommitted
net: ipv4: relax AF_INET check in bind()
commit d0733d2 (Check for mistakenly passed in non-IPv4 address) added regression on legacy apps that use bind() with AF_UNSPEC family. Relax the check, but make sure the bind() is done on INADDR_ANY addresses, as AF_UNSPEC has probably no sane meaning for other addresses. Bugzilla reference : https://bugzilla.kernel.org/show_bug.cgi?id=42012 Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Reported-and-bisected-by: Rene Meier <r_meier@freenet.de> CC: Marcus Meissner <meissner@suse.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7858241 commit 29c486d

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

net/ipv4/af_inet.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,13 @@ int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
466466
goto out;
467467

468468
if (addr->sin_family != AF_INET) {
469+
/* Compatibility games : accept AF_UNSPEC (mapped to AF_INET)
470+
* only if s_addr is INADDR_ANY.
471+
*/
469472
err = -EAFNOSUPPORT;
470-
goto out;
473+
if (addr->sin_family != AF_UNSPEC ||
474+
addr->sin_addr.s_addr != htonl(INADDR_ANY))
475+
goto out;
471476
}
472477

473478
chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);

0 commit comments

Comments
 (0)