socket lock dances inside network stack #607

Open
opened 2026-07-25 16:09:59 +00:00 by hidnplayr · 0 comments
Owner

There are several code paths inside network stack which cause repeated lock→ unlock→ relock of the socket mutex.
Not only is it inefficient, another thread could sneak in between the calls causing various havoc.
When the lock is re-acquired, the state of the socket might have changed, or it might even no longer exist.

The following problematic sequences have been identified:

Location Pattern Risk
Accept / socket_fork Unlock listening socket → create+lock child Race on listening socket while fork runs
Various entry points (e.g. tcp_input) unlock → tcp_output → relock state altered before output
Pure-ACK header prediction Unlock → notify → tcp_output → never relock Window after unlock
tcp_close call sites Unlock → tcp_close Depends on whether tcp_close re-locks
Various .drop* / final paths Unlock and leave Lifetime window (to be fixed by #606)
socket_ring_read Unlock before copy Data race on the ring (to be fixed by #606)
There are several code paths inside network stack which cause repeated lock→ unlock→ relock of the socket mutex. Not only is it inefficient, another thread could sneak in between the calls causing various havoc. When the lock is re-acquired, the state of the socket might have changed, or it might even no longer exist. The following problematic sequences have been identified: | Location | Pattern | Risk | | --- | --- | --- | | Accept / socket_fork | Unlock listening socket → create+lock child | Race on listening socket while fork runs | | Various entry points (e.g. tcp_input) | unlock → tcp_output → relock | state altered before output | | Pure-ACK header prediction | Unlock → notify → tcp_output → never relock | Window after unlock | | tcp_close call sites | Unlock → tcp_close | Depends on whether tcp_close re-locks | | Various .drop* / final paths | Unlock and leave | Lifetime window (to be fixed by #606) | | socket_ring_read | Unlock before copy | Data race on the ring (to be fixed by #606) |
hidnplayr added the
Category
Kernel
Kind
Bug
Lang/FASM
Priority
High
2
Subsystem/Network
labels 2026-07-25 16:41:11 +00:00
hidnplayr self-assigned this 2026-07-25 16:41:17 +00:00
hidnplayr added this to the Network stack project 2026-08-02 15:56:38 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: KolibriOS/kolibrios#607