Page MenuHomeFreeBSD

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

Authored by karels on Aug 2 2022, 1:06 PM.
Tags
None
Referenced Files
F81577537: D36012.diff
Thu, Apr 18, 9:38 AM
Unknown Object (File)
Mar 17 2024, 12:26 PM
Unknown Object (File)
Mar 17 2024, 7:29 AM
Unknown Object (File)
Jan 27 2024, 11:03 AM
Unknown Object (File)
Jan 17 2024, 4:05 PM
Unknown Object (File)
Jan 12 2024, 6:48 AM
Unknown Object (File)
Jan 10 2024, 3:30 PM
Unknown Object (File)
Dec 29 2023, 11:21 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
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

karels requested review of this revision.Aug 2 2022, 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.Aug 2 2022, 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.