Use-after-free on TabStatsDataStore::OnTabReplaced |
||||
Issue descriptionThere's a UAF in TabStatsDataStore::OnTabReplaced caused by this change: https://chromium-review.googlesource.com/c/chromium/src/+/867073/2/chrome/browser/metrics/tab_stats_data_store.cc#90 The problematic line of code is this one: existing_tabs_[new_contents] = existing_tabs_[old_contents]; here existing_tabs_ is a flat_map, the problem is that iterator and references returned by operator[] are not stable when using a flat_map. In this particular case the reference to |existing_tabs_[old_contents]| gets pushed onto the stack before evaluating |existing_tabs_[new_contents]|, which might require the underlying vector used by the flat_map to grow as it's adding an element to it, in this case the reference to |existing_tabs_[old_contents]| will be invalid (it'll point to the previous flat_map underlying vector). (see report https://crash.corp.google.com/browse?q=reportid=%2765b751228ac53ab5%27)
,
Jan 19 2018
I forgot to mention it here but I'll fix this by using a temporary variable to hold the return value of |existing_tabs_[old_contents]|
,
Jan 20 2018
I'm not sure: on one hand, I feel like it's kind of implied since the underlying collection is backed by a vector, but on the other, I can understand it's kind of surprising. I'd probably just update the class usage notes to mention that this applies to references returned from operator[] as well: there's already a bullet point that says "Iterators are invalidated across mutations".
,
Jan 24 2018
My suggestion would be to just update the comment you're referring to to: "Iterators and references returned by operator[] are invalidated across mutations". +etienneb@ said that it'd be trivial to write a linter for this pattern, it's quite easy to make this mistake (e.g. you replace a map class member by a flat_map but you fail to notice that there's a foo[a] = foo[b] in the code), so I wouldn't be too surprised if there was more occurrences of this.
,
Feb 7 2018
|
||||
►
Sign in to add a comment |
||||
Comment 1 by sebmarchand@chromium.org
, Jan 19 2018