Bug 182365 - [JSCOnly] Ensure RunLoop::Timer is robust to being deleted inside its user callback
Summary: [JSCOnly] Ensure RunLoop::Timer is robust to being deleted inside its user ca...
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: Other
Hardware: PC Linux
: P2 Normal
Assignee: Michael Catanzaro
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-31 16:54 PST by Michael Catanzaro
Modified: 2018-02-01 06:51 PST (History)
7 users (show)

See Also:


Attachments
Patch (1.37 KB, patch)
2018-01-31 17:04 PST, Michael Catanzaro
mcatanzaro: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Catanzaro 2018-01-31 16:54:47 PST
Ensure RunLoop::Timer is robust to being deleted inside its user callback. This is a theoretical issue that I noticed as the result of an actual use-after-free caught by asan in WPE and GTK. See bug #182271. It's not actually possible to test the original reproducer using JSCOnly, because it was a WebKit-layer problem.

I'm going to attach a totally-untested, speculative fix for the theoretical issue. I think it's correct.
Comment 1 Michael Catanzaro 2018-01-31 17:04:48 PST
Created attachment 332825 [details]
Patch
Comment 2 Michael Catanzaro 2018-01-31 17:08:59 PST
This should be reviewed by Yusuke, because I'm really not sure whether it's necessary or not. If the RunLoop itself is guaranteed to have another ref on the ScheduledTask, then this isn't needed.
Comment 3 Yusuke Suzuki 2018-02-01 00:27:29 PST
(In reply to Michael Catanzaro from comment #2)
> This should be reviewed by Yusuke, because I'm really not sure whether it's
> necessary or not. If the RunLoop itself is guaranteed to have another ref on
> the ScheduledTask, then this isn't needed.

I don't think it is necessary. See L173. When calling ScheduledTask::fired(), RunLoop's code always has ref by `RefPtr<ScheduledTask>`.
BTW, this problem is why I separate ScheduledTask from TimerBase IIRC :)
Comment 4 Michael Catanzaro 2018-02-01 06:51:20 PST
(In reply to Yusuke Suzuki from comment #3)
> I don't think it is necessary. See L173. When calling
> ScheduledTask::fired(), RunLoop's code always has ref by
> `RefPtr<ScheduledTask>`.
> BTW, this problem is why I separate ScheduledTask from TimerBase IIRC :)

Good decision ;)