mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-22 22:32:42 +00:00
Introduce StableStack to avoid UAF into Context stacks (#8055)
Stacks in Context can grow when eval is run, and if they are implemented as SmallVector, the growing can cause a reallocation. Meanwhile for stacks that hold larger structs/classes, we hold onto the pointer into the stack instead of copying out. This can cause a UAF when reallocation happens. StableStack never reallocates when growing, as it is represented by a vector of pointers to arrays, where each array is a factor larger than the previous one. This prevents UAF from occurring when we run eval while holding a pointer into a stack. This solves a similar problem that our ValuesStores previously solved in #5576. In that case, we also represent them as a vector of pointers to arrays. The difference being our ValueStores are meant to grow but not shrink, and they are built around the ID concept where IDs happen to be an index into the store.
This commit is contained in:
1 parent
4a46ea888f
commit
30318f87f7
12 files changed
+1019
-29
No files matched your search
@@ -14,7 +14,7 @@ auto GenericRegionStack::Push(PendingGeneric generic) -> void {
|
||||
pending_generic_ids_.push_back(generic);
|
||||
pending_eval_block_stack_.PushArray();
|
||||
dependent_inst_stack_.PushArray();
|
||||
constants_in_generic_stack_.emplace_back();
|
||||
constants_in_generic_stack_.Emplace();
|
||||
}
|
||||
|
||||
auto GenericRegionStack::Pop() -> void {
|
||||
@@ -23,7 +23,7 @@ auto GenericRegionStack::Pop() -> void {
|
||||
pending.region);
|
||||
pending_eval_block_stack_.PopArray();
|
||||
dependent_inst_stack_.PopArray();
|
||||
constants_in_generic_stack_.pop_back();
|
||||
constants_in_generic_stack_.Pop();
|
||||
}
|
||||
|
||||
} // namespace Carbon::Check
|
||||
Reference in new issue
Block a user