Skip to content

TCPIP: make the return value of network_socket_accept_tcp more expressive - #107

Open
nding0405 wants to merge 1 commit into
CHERIoT-Platform:mainfrom
nding0405:fix-accept-return-value
Open

TCPIP: make the return value of network_socket_accept_tcp more expressive#107
nding0405 wants to merge 1 commit into
CHERIoT-Platform:mainfrom
nding0405:fix-accept-return-value

Conversation

@nding0405

Copy link
Copy Markdown
Contributor

The network_socket_accept_tcp function can only return either a valid sealed capability or an untagged nullptr, so the caller cannot distinguish a timeout from an out-of-memory failure. Change it so that it can return an invalid capability that encodes the error code.

…sive

The network_socket_accept_tcp function can only return either a valid
sealed capability or an untagged nullptr, so the caller cannot distinguish
a timeout from an out-of-memory failure. Change it so that it can return
an invalid capability that encodes the error code.
@nding0405
nding0405 force-pushed the fix-accept-return-value branch from 860576b to bd3fa50 Compare July 23, 2026 19:25
nding0405 added a commit to nding0405/network-stack that referenced this pull request Jul 23, 2026
This patch completes the fix for issue CHERIoT-Platform#104. PR CHERIoT-Platform#107 added an
ephemeral claim in with_sealed_socket(), protecting the
SealedSocket wrapper until the first cross-compartment call. In
network_socket_close(), that protection ends at heap_can_free().
In the post-reset close path, the socket lock cannot be acquired, so
any later dereference of the wrapper may race with another thread
freeing the wrapper and cause a Use-After-Free. The normal close path
is not affected because the wrapper remains protected by socketLock.

To remove this race, the fields needed after heap_can_free() are
copied from the wrapper before the cross call, and the wrapper is not
dereferenced afterward in the post-reset path. The raw FreeRTOS socket
is also vulnerable in rawSocket->ucProtocol; because this value is
needed only for the normal close path, but the current codebase make it
accesible for both nomal close and post-reset close, ane the later path
can produce an UAF on that line of code. Thus, to fix this, the dereference
is moved inside the lock-protected branch.

These changes eliminate both wrapper and raw-socket UAF from the unprotected
post-reset path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant