Busy port checking during port autoselection for wildcard-port bind() is incomplete, and this may lead to binding to already busy port and EADDRINUSE from connect().
The same problem for implicit bind when connecting from unbound socket was fixed in r361228.
There is two know ways to trigger this:
- make a connection from bind(0.0.0.0:0) to any address;
then repeat the same from a jail;
jailed bind() doesn't know about the port busy by first one and may erroneously try to reuse it, leading to EADDRINUSE from connect()
- make a connection from bind(ipv6 :::0) to ipv6-wrapper ipv4 address, for example ::ffff:127.0.0.1:10001;
then just repeat the same again;
second bind() doesn't know about first one, because first one became "ipv4" after connecting, so it may try reuse the same port and connect() will fail with EADDRINUSE
PR: 210726
PR: 265064