Page MenuHomeFreeBSD

socket: Fix a race between kevent(2) and listen(2)
ClosedPublic

Authored by markj on Jun 15 2022, 1:12 PM.
Tags
None
Referenced Files
F107537600: D35492.diff
Wed, Jan 15, 2:34 PM
Unknown Object (File)
Tue, Dec 17, 8:51 AM
Unknown Object (File)
Dec 14 2024, 6:26 AM
Unknown Object (File)
Dec 1 2024, 5:04 AM
Unknown Object (File)
Nov 29 2024, 7:36 AM
Unknown Object (File)
Nov 24 2024, 6:10 AM
Unknown Object (File)
Nov 23 2024, 10:58 AM
Unknown Object (File)
Nov 22 2024, 1:51 PM
Subscribers

Details

Summary

When locking the knote list for a socket, we check whether the socket is
a listening socket in order to select the appropriate mutex; a listening
socket uses the socket lock, while data sockets use socket buffer
mutexes.

If SOLISTENING(so) is false and the knote lock routine locks a socket
buffer, then it must re-check whether the socket is a listening socket
since solisten_proto() could have changed the socket's identity.

Reported by: syzkaller

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 45987
Build 42875: arc lint + arc unit

Event Timeline

markj requested review of this revision.Jun 15 2022, 1:12 PM

Thanks, Mark!

If I was writing this I would prefer goto over for(;;) and break as human reading of the code should be that looping here is extremely unprobable:

retry:
if (SOLISTENING(so))
        SOLISTEN_LOCK(so);
else {
        SOCK_RECVBUF_LOCK(so);
        if (__predict_false(SOLISTENING(so))) {
                  SOCK_RECVBUF_UNLOCK(so);
                  goto retry;
        }
}
This revision is now accepted and ready to land.Jun 15 2022, 7:19 PM
This revision now requires review to proceed.Jun 15 2022, 8:08 PM
This revision was not accepted when it landed; it landed in state Needs Review.Jun 16 2022, 2:36 PM
This revision was automatically updated to reflect the committed changes.