Repository navigation
Commit 0208108
[M151] Fix Use-After-Free in SubRunAllocator
Original change's description:
> Fix Use-After-Free in SubRunAllocator
>
> The destruction order of `std::tuple` members is not specified by the
> C++ standard. This is the root cause of a Use-After-Free (UAF) in
> SubRunAllocator. Replacing the tuple with a custom struct resolves the
> issue by guaranteeing the correct destruction order.
>
> The Bug:
> During deserialization of a Slug (specifically in
> SlugImpl::MakeFromBuffer), if the input buffer is invalid or corrupted,
> Skia detects this and returns nullptr early.
>
> This early return destroys the temporary return value. In the old code
> (using `std::tuple`), `SubRunInitializer` (index 0) was destructed
> first and freed the backing memory.
>
> `SubRunAllocator` (index 2) was destructed next. Its destructor
> (~BagOfBytes) then attempted to access fEndByte (which points inside
> the freed memory), resulting in a UAF (read) followed by a wild-free
> or double-free.
>
> The Fix:
> We replaced the `std::tuple` with a custom helper struct
> `AllocateAndArenaResult`:
>
> struct AllocateAndArenaResult {
> SubRunInitializer<T> initializer; // Destructed last
> int totalMemorySize;
> SubRunAllocator alloc; // Destructed first
> };
>
> Since struct members are guaranteed to be destructed in the reverse
> order of their declaration, declaring `alloc` last guarantees it is
> destructed before `SubRunInitializer` frees the memory.
>
> Additionally, this CL refactors `SubRunInitializer` to use
> `std::unique_ptr` with a custom deleter to manage the raw memory,
> removing the need for a manual destructor and making the ownership
> transfer explicit via `release()`.
>
> Bug: skia:530646115
> Change-Id: I80cba4fdb9eebfe16e5ec837d70b5646422fbcff
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1284796
> Commit-Queue: Kaylee Lubick <[email protected]>
> Reviewed-by: Kaylee Lubick <[email protected]>
(cherry picked from commit 014a77e)
Bug: 532103445,skia:530646115
Change-Id: I80cba4fdb9eebfe16e5ec837d70b5646422fbcff
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1288616
Bot-Commit: [email protected] <[email protected]>
Auto-Submit: Chrome Cherry Picker <chrome-cherry-picker@chops-service-accounts.iam.gserviceaccount.com>
Commit-Queue: [email protected] <[email protected]>1 parent 1536d39 commit 0208108
1 file changed
Lines changed: 45 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
| 191 | + | |
| 192 | + | |
195 | 193 | | |
196 | 194 | | |
197 | 195 | | |
198 | 196 | | |
199 | | - | |
| 197 | + | |
200 | 198 | | |
201 | 199 | | |
202 | 200 | | |
203 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
204 | 209 | | |
205 | 210 | | |
206 | | - | |
207 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
208 | 215 | | |
209 | 216 | | |
210 | 217 | | |
| |||
234 | 241 | | |
235 | 242 | | |
236 | 243 | | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
| 244 | + | |
| 245 | + | |
251 | 246 | | |
252 | 247 | | |
253 | 248 | | |
| |||
328 | 323 | | |
329 | 324 | | |
330 | 325 | | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
331 | 354 | | |
332 | 355 | | |
333 | 356 | | |
| |||
0 commit comments