Skip to content

Keep the iovec buffers alive until the kernel reads them - #13

Merged
gronke merged 2 commits into
mainfrom
fix/iovec-keepalive
Jul 8, 2026
Merged

Keep the iovec buffers alive until the kernel reads them#13
gronke merged 2 commits into
mainfrom
fix/iovec-keepalive

Conversation

@gronke

@gronke gronke commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Building a Jiov cast unreferenced temporaries to void pointers, so jail_set(2) could hand the kernel addresses of memory that Python had already freed - it worked by allocator luck.

  • Keys and values now own their backing buffers for their whole lifetime, and every iov_base points at that owned memory; reassigning a value invalidates its buffer.
  • The errmsg pair keeps its key buffer on the Jiov and no longer takes the address through an ill-typed POINTER(c_char_p) construction.
  • A unit test reads every iovec entry back from its raw addresses after garbage collection and allocator churn; an integration test creates a jail under the same conditions and resolves it by name.

gronke added 2 commits July 8, 2026 07:41
The iovec builders cast unreferenced temporaries to void pointers and the array construction in Jiov.struct copies structures without their keepalives, so the kernel could read freed memory whenever the allocator reused those blocks before jail_set(2).
Keys and values now retain their backing buffers, invalidated when a value is reassigned, and every iov_base points at owned memory through ctypes.addressof.
The errmsg pair keeps its key buffer on the Jiov and no longer takes the buffer address through an ill-typed POINTER(c_char_p) construction.
The unit test rebuilds every entry of the iovec array from its raw addresses after provoking allocator reuse.
The integration test creates a jail under the same conditions and resolves it by name through jail_get(2).
@gronke
gronke merged commit f1bee04 into main Jul 8, 2026
4 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.

1 participant