Skip to content

TCP/IP: Fix UAF in network_socket_close() - #108

Merged
davidchisnall merged 1 commit into
CHERIoT-Platform:mainfrom
nding0405:fix-socket-close-UAF
Jul 30, 2026
Merged

TCP/IP: Fix UAF in network_socket_close()#108
davidchisnall merged 1 commit into
CHERIoT-Platform:mainfrom
nding0405:fix-socket-close-UAF

Conversation

@nding0405

Copy link
Copy Markdown
Contributor

This patch completes the fix for issue #104 . PR #106 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.

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.
@nding0405
nding0405 force-pushed the fix-socket-close-UAF branch from d708a32 to d9aea6b Compare July 23, 2026 22:36
@davidchisnall
davidchisnall merged commit 7d04987 into CHERIoT-Platform:main Jul 30, 2026
9 of 10 checks passed
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.

2 participants