Bug 188281 - JSLock::ownerThread seems racy
Summary: JSLock::ownerThread seems racy
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Saam Barati
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-08-02 15:35 PDT by Saam Barati
Modified: 2019-01-20 14:50 PST (History)
13 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Saam Barati 2018-08-02 15:35:26 PDT
Specifically, the race I'm worried about is:

```
m_ownerThread = ...; // set to non null value some time long ago.
T1: VMTraps signal sender thread.
T2: VM main execution thread.

T1: tmp1 = m_ownerThread.m_ptr;
T2: tmp2 = m_ownerThread.m_ptr;
T2: m_ownerThread.m_ptr = nullptr;
T2: tmp2->deref(); // ref count going from 1->0
T2: ~(tmp2);
T1: tmp1->ref(); // UAF
```

Would be helpful if somebody else looked to see if there are errors in my logic here.
Comment 1 Saam Barati 2018-08-02 15:43:20 PDT
(In reply to Saam Barati from comment #0)
> Specifically, the race I'm worried about is:
> 
> ```
> m_ownerThread = ...; // set to non null value some time long ago.
> T1: VMTraps signal sender thread.
> T2: VM main execution thread.
> 
> T1: tmp1 = m_ownerThread.m_ptr;
> T2: tmp2 = m_ownerThread.m_ptr;
> T2: m_ownerThread.m_ptr = nullptr;
> T2: tmp2->deref(); // ref count going from 1->0
> T2: ~(tmp2);
> T1: tmp1->ref(); // UAF
> ```
> 
> Would be helpful if somebody else looked to see if there are errors in my
> logic here.

actually, it'd look somewhat different, since we never null out that pointer, we just assign new pointers in, but race still holds I think:


```
m_ownerThread = ...; // set to non null a long time ago
T1: VMTraps signal sender thread.
T2: VM main execution thread.

T1: tmp1 = m_ownerThread.m_ptr;
T2: tmp2 = m_ownerThread.m_ptr;
T2: m_ownerThread.m_ptr = some other ptr;
T2: tmp2->deref(); // ref count going from 1->0
T2: ~(tmp2);
T1: tmp1->ref(); // UAF
```
Comment 2 Radar WebKit Bug Importer 2019-01-20 14:50:33 PST
<rdar://problem/47417563>