Title: [247322] trunk/Source/WebKit
- Revision
- 247322
- Author
- [email protected]
- Date
- 2019-07-10 13:10:49 -0700 (Wed, 10 Jul 2019)
Log Message
Crash under IPC::Connection::waitForMessage()
https://bugs.webkit.org/show_bug.cgi?id=199680
<rdar://problem/52500561>
Reviewed by Tim Horton.
IPC::Connection::waitForMessage() is crashing due to a null defererence of
m_waitingForMessage. Since m_waitingForMessage is only ever set to null in
waitForMessage(), this seems to imply we've re-entered waitForMessage().
This is in theory possible since the loop inside waitForMessage() calls
SyncMessageState::singleton().dispatchMessages() on every iteration to
process incoming synchronous IPC messages. In theory, one of these sync
IPC messages could run code which ends up calling waitForAndDispatchImmediately()
(and thus waitForMessage()).
We had a debug assertion to try and catch re-entrancy with a comment stating
"We don't support having multiple clients waiting for messages." but we
would not see those in release and we would crash with a null dereference
instead.
To address the crashes in release, return early in case of re-entrancy
(we would still hit an assertion in debug).
* Platform/IPC/Connection.cpp:
(IPC::Connection::Connection):
(IPC::Connection::waitForMessage):
* Platform/IPC/Connection.h:
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (247321 => 247322)
--- trunk/Source/WebKit/ChangeLog 2019-07-10 20:04:26 UTC (rev 247321)
+++ trunk/Source/WebKit/ChangeLog 2019-07-10 20:10:49 UTC (rev 247322)
@@ -1,3 +1,33 @@
+2019-07-10 Chris Dumez <[email protected]>
+
+ Crash under IPC::Connection::waitForMessage()
+ https://bugs.webkit.org/show_bug.cgi?id=199680
+ <rdar://problem/52500561>
+
+ Reviewed by Tim Horton.
+
+ IPC::Connection::waitForMessage() is crashing due to a null defererence of
+ m_waitingForMessage. Since m_waitingForMessage is only ever set to null in
+ waitForMessage(), this seems to imply we've re-entered waitForMessage().
+ This is in theory possible since the loop inside waitForMessage() calls
+ SyncMessageState::singleton().dispatchMessages() on every iteration to
+ process incoming synchronous IPC messages. In theory, one of these sync
+ IPC messages could run code which ends up calling waitForAndDispatchImmediately()
+ (and thus waitForMessage()).
+
+ We had a debug assertion to try and catch re-entrancy with a comment stating
+ "We don't support having multiple clients waiting for messages." but we
+ would not see those in release and we would crash with a null dereference
+ instead.
+
+ To address the crashes in release, return early in case of re-entrancy
+ (we would still hit an assertion in debug).
+
+ * Platform/IPC/Connection.cpp:
+ (IPC::Connection::Connection):
+ (IPC::Connection::waitForMessage):
+ * Platform/IPC/Connection.h:
+
2019-07-10 Tim Horton <[email protected]>
Context menus are not presented for WKWebViews that don't have UIDelegates
Modified: trunk/Source/WebKit/Platform/IPC/Connection.cpp (247321 => 247322)
--- trunk/Source/WebKit/Platform/IPC/Connection.cpp 2019-07-10 20:04:26 UTC (rev 247321)
+++ trunk/Source/WebKit/Platform/IPC/Connection.cpp 2019-07-10 20:10:49 UTC (rev 247322)
@@ -260,7 +260,6 @@
, m_inDispatchMessageCount(0)
, m_inDispatchMessageMarkedDispatchWhenWaitingForSyncReplyCount(0)
, m_didReceiveInvalidMessage(false)
- , m_waitingForMessage(nullptr)
, m_shouldWaitForSyncReplies(true)
{
ASSERT(RunLoop::isMain());
@@ -468,6 +467,7 @@
std::unique_ptr<Decoder> Connection::waitForMessage(StringReference messageReceiverName, StringReference messageName, uint64_t destinationID, Seconds timeout, OptionSet<WaitForOption> waitForOptions)
{
ASSERT(RunLoop::isMain());
+ auto protectedThis = makeRef(*this);
timeout = timeoutRespectingIgnoreTimeoutsForTesting(timeout);
@@ -494,7 +494,11 @@
// Don't even start waiting if we have InterruptWaitingIfSyncMessageArrives and there's a sync message already in the queue.
if (hasIncomingSynchronousMessage && waitForOptions.contains(WaitForOption::InterruptWaitingIfSyncMessageArrives)) {
- m_waitingForMessage = nullptr;
+#if !ASSERT_DISABLED
+ std::lock_guard<Lock> lock(m_waitForMessageMutex);
+ // We don't support having multiple clients waiting for messages.
+ ASSERT(!m_waitingForMessage);
+#endif
return nullptr;
}
@@ -505,6 +509,8 @@
// We don't support having multiple clients waiting for messages.
ASSERT(!m_waitingForMessage);
+ if (m_waitingForMessage)
+ return nullptr;
m_waitingForMessage = &waitingForMessage;
}
Modified: trunk/Source/WebKit/Platform/IPC/Connection.h (247321 => 247322)
--- trunk/Source/WebKit/Platform/IPC/Connection.h 2019-07-10 20:04:26 UTC (rev 247321)
+++ trunk/Source/WebKit/Platform/IPC/Connection.h 2019-07-10 20:10:49 UTC (rev 247322)
@@ -353,7 +353,7 @@
HashMap<uint64_t, ReplyHandler> m_replyHandlers;
struct WaitForMessageState;
- WaitForMessageState* m_waitingForMessage;
+ WaitForMessageState* m_waitingForMessage { nullptr };
class SyncMessageState;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes