Skip to content

types: fix potential use after free on adding keys during iteration#239

Merged
jow- merged 1 commit into
masterfrom
safe-insert-during-obj-iteration
Oct 17, 2024
Merged

types: fix potential use after free on adding keys during iteration#239
jow- merged 1 commit into
masterfrom
safe-insert-during-obj-iteration

Conversation

@jow-

@jow- jow- commented Oct 16, 2024

Copy link
Copy Markdown
Owner

When keys are added to the object currently being iterated by a for loop, the insert operation might cause a hashtable resize with a subsequent memory reallocation and a different table base pointer, clobbering the entry pointers held by iterators pointing to the containing object of the resized table.

In order to address this issue while keeping the iteration overhead low, extend the object key insert logic to check whether the insertion will trigger a reallocation and backup and restore the iterator pointers when needed.

This slightly increases the size of the iterator states but the overhead for this should be neglectible as there'll only be a low amount of concurrently active iterations at any time.

Fixes: #230

When keys are added to the object currently being iterated by a for loop,
the insert operation might cause a hashtable resize with a subsequent
memory reallocation and a different table base pointer, clobbering the
entry pointers held by iterators pointing to the containing object of the
resized table.

In order to address this issue while keeping the iteration overhead low,
extend the object key insert logic to check whether the insertion will
trigger a reallocation and backup and restore the iterator pointers when
needed.

This slightly increases the size of the iterator states but the overhead
for this should be neglectible as there'll only be a low amount of
concurrently active iterations at any time.

Fixes: #230
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
@jow- jow- force-pushed the safe-insert-during-obj-iteration branch from c58966c to 736d450 Compare October 17, 2024 07:15
@jow- jow- merged commit 402280d into master Oct 17, 2024
@jow- jow- deleted the safe-insert-during-obj-iteration branch October 17, 2024 14:32
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.

Use-After-Free: Adding object keys during iteration

1 participant