Fix use-after-free in mrb_obj_alloc()#6329
Merged
Merged
Conversation
Member
|
I don't think the function name |
When GC occurs during the expansion of the GC arena by `gc_protect()` in `mrb_obj_alloc()`, the object page just allocated by `add_heap()` is released. Therefore, as soon as control returns from `gc_protect()`, there is a possibility of illegal writing or reading to the address just released. This issue was discovered during the investigation of mruby#6326.
adaa27d to
1c5839f
Compare
Contributor
Author
|
Thanks for the review. 「order」は「注文」の意味で使ってました。 |
dearblue
added a commit
to dearblue/mruby
that referenced
this pull request
Aug 25, 2024
This was the unintentional catalyst for finding the problem in mruby#6329, but it is preferable to add a test if necessary.
matz
added a commit
that referenced
this pull request
Aug 25, 2024
matz
added a commit
that referenced
this pull request
Sep 3, 2024
We assumed there's no need for gc_arena_keep() when MRB_GC_FIXED_ARENA is set. But it turned out that gc_protect() still can cause use-after-free with fixed arena. Revert "gc.c (gc_protect): should not call gc_arena_keep twice from allocation" This reverts commit 28ece4e. Revert "gc.c (gc_arena_keep): reorganized for MRB_GC_FIXED_ARENA; ref #6329" This reverts commit 33dd623.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When GC occurs during the expansion of the GC arena by
gc_protect()inmrb_obj_alloc(), the object page just allocated byadd_heap()is released.Therefore, as soon as control returns from
gc_protect(), there is a possibility of illegal writing or reading to the address just released.This issue was discovered during the investigation of #6326.
I think this problem can be seen in the following build configuration file.
The key is to define
MRB_HEAP_PAGE_SIZE=1.