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
Unknown Object (File)
Fri, Jan 24, 12:07 PM
Unknown Object (File)
Wed, Jan 22, 10:42 AM
Unknown Object (File)
Jan 1 2025, 2:13 AM
Unknown Object (File)
Dec 6 2024, 5:28 AM
Unknown Object (File)
Nov 26 2024, 6:21 PM
Unknown Object (File)
Nov 25 2024, 1:27 AM
Unknown Object (File)
Nov 23 2024, 11:27 PM
Unknown Object (File)
Nov 23 2024, 8:34 AM

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

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.