Page MenuHomeFreeBSD

IPv6: fix problem with duplicate port assignment with v4-mapped addrs
ClosedPublic

Authored by karels on Tue, Aug 2, 1:06 PM.

Details

Summary

In in_pcb_lport_dest(), if an IPv6 socket does not match any other IPv6
socket using in6_pcblookup_local(), and if the socket can also connect
to IPv4 (the INP_IPV4 vflag is set), check for IPv4 matches as well.
Otherwise, we can allocate a port that is used by an IPv4 socket
(possibly one created from IPv6 via the same procedure), and then
connect() can fail with EADDRINUSE, when it could have succeeded if
the bound port was not in use.

Test Plan

used test program and Go test that pointed out the problem

Diff Detail

Repository
rG FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

karels requested review of this revision.Tue, Aug 2, 1:06 PM

Notes:

PR https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=265064

Based on fix by firk@cantconnect.ru in that PR, but simplified a little and without the fix for PR 210726 (using NULL credentials).

This revision is now accepted and ready to land.Tue, Aug 2, 1:17 PM

It looks great, my only concern is that this case it easily forgotten - personally I'm pretty sure I may forget this special case when touching pcb hash.
Would it be possible to add a small test so we have automation to monitor if that's still working?

Would it be possible to add a small test so we have automation to monitor if that's still working?

I'll take a look at that. The PR has a substantial test program, but I'd want something simpler (e.g. without threads). The test program will need to manipulate the portrange so it runs in a small time. I'll try to do this soon.