Bug 209042 - reportZappedCellAndCrash should handle PreciseAllocation in IsoSubspace
Summary: reportZappedCellAndCrash should handle PreciseAllocation in IsoSubspace
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-03-13 00:28 PDT by Yusuke Suzuki
Modified: 2020-03-15 03:52 PDT (History)
11 users (show)

See Also:


Attachments
Patch (5.19 KB, patch)
2020-03-13 18:08 PDT, Yusuke Suzuki
mark.lam: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2020-03-13 00:28:57 PDT
Let's extend.
Comment 1 Yusuke Suzuki 2020-03-13 18:08:31 PDT
Created attachment 393567 [details]
Patch
Comment 2 Yusuke Suzuki 2020-03-14 14:59:11 PDT
To collect more cell info in ASan bots.
Comment 3 Mark Lam 2020-03-14 15:41:50 PDT
Comment on attachment 393567 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=393567&action=review

> Source/JavaScriptCore/runtime/JSCell.cpp:387
> +            variousState |= static_cast<uint64_t>(!isFreeListed) << 1;

Is this correct?  Does !!isFreeListed mean isAllocated?
Comment 4 Mark Lam 2020-03-14 15:42:52 PDT
(In reply to Mark Lam from comment #3)
> Comment on attachment 393567 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=393567&action=review
> 
> > Source/JavaScriptCore/runtime/JSCell.cpp:387
> > +            variousState |= static_cast<uint64_t>(!isFreeListed) << 1;
> 
> Is this correct?  Does !!isFreeListed mean isAllocated?

typo: I meant !isFreeListed
Comment 5 Mark Lam 2020-03-14 17:25:45 PDT
Comment on attachment 393567 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=393567&action=review

r=me

>>> Source/JavaScriptCore/runtime/JSCell.cpp:387
>>> +            variousState |= static_cast<uint64_t>(!isFreeListed) << 1;
>> 
>> Is this correct?  Does !!isFreeListed mean isAllocated?
> 
> typo: I meant !isFreeListed

Nevermind, I've read thru the PreciseAllocation code and this patch some more.  This is correct because foundPreciseAllocation is only true if this cell is found in the lower tier of this IsoSubspace, and it is only allocated if it's not on the free list.

> Source/JavaScriptCore/runtime/JSCell.cpp:390
> +                variousState |= static_cast<uint64_t>(foundPreciseAllocation->isEmpty()) << 2;
> +                variousState |= static_cast<uint64_t>(foundPreciseAllocation->isNewlyAllocated()) << 4;

The isEmpty and isNewlyAllocated flags previously meant that the cell pointer was found in a MarkedBlock of that state.  For PreciseAllocations, I think knowing whether it isFreeListed or isAllocated is sufficient.  I'm not quite sure what isEmpty and isNewlyAllocated would mean in this case.  I suggest just leaving these unset.

Instead, can you also set the cellIsProperlyAligned flag ( << 5) in variousState based on whether (foundPreciseAllocation->cell() == cell)?  If the cell pointer is found in a PreciseAllocation but does not equal it's expected cell() pointer, then we have a corrupted pointer or someone unscrupulous is making bad pointers.

Can you also set the needsDestruction flag in variousState based on whether the SubSpace CellAttributes says it NeedsDestruction or not?
Comment 6 Yusuke Suzuki 2020-03-15 03:41:55 PDT
Comment on attachment 393567 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=393567&action=review

>> Source/JavaScriptCore/runtime/JSCell.cpp:390
>> +                variousState |= static_cast<uint64_t>(foundPreciseAllocation->isNewlyAllocated()) << 4;
> 
> The isEmpty and isNewlyAllocated flags previously meant that the cell pointer was found in a MarkedBlock of that state.  For PreciseAllocations, I think knowing whether it isFreeListed or isAllocated is sufficient.  I'm not quite sure what isEmpty and isNewlyAllocated would mean in this case.  I suggest just leaving these unset.
> 
> Instead, can you also set the cellIsProperlyAligned flag ( << 5) in variousState based on whether (foundPreciseAllocation->cell() == cell)?  If the cell pointer is found in a PreciseAllocation but does not equal it's expected cell() pointer, then we have a corrupted pointer or someone unscrupulous is making bad pointers.
> 
> Can you also set the needsDestruction flag in variousState based on whether the SubSpace CellAttributes says it NeedsDestruction or not?

I think isNewlyAllocated (In Eden or not) is nice to have. And isEmpty is also nice too (WeakSet is claered etc.). I'm querying this only when `!isFreeListed` since (1) isNewlyAllocated is meaningless if it is not in free list and (2) if this cell is not in freelist, we are not guaranteeing that WeakSet (isEmpty is accessing this) is not broken.
Adding cellIsProperlyAligned sounds nice. Fixed. Not sure whether NeedsDestruction is important since this can be super easily detected based on IsoSubspace, but maybe it would be ok. Added.
Comment 7 Yusuke Suzuki 2020-03-15 03:51:09 PDT
Committed r258479: <https://trac.webkit.org/changeset/258479>
Comment 8 Radar WebKit Bug Importer 2020-03-15 03:52:15 PDT
<rdar://problem/60466867>