Generic cancellation for async-with-reply IPC messages
Component: WebKit IPC | 0f6a044
LayoutTests/ipc/send-ignored-network-message.html
LayoutTests/ipc/removeMediaUsageManagerSession-test.html
WebKit's processes talk over messages defined in .messages.in files, which a Python generator (messages.py) turns into name enums, receiver dispatch, and send/reply glue. An async-with-reply message carries an AsyncReplyID, and the sender stores a completion handler keyed by that ID. Until now, a message the receiver dropped left that handler pending until connection invalidation, unless the interface opted into WantsSendCancelReply.
Now, if MessageReceiver::didReceiveMessage never calls Decoder::markHandled(), the receiver sends a new CancelAsyncReply protocol message, replacing the per-interface attribute. The sender's handler runs with the connection and a null decoder, promised replies reject with Error::AsyncReplyCancelled, and waiting for an async reply completes on cancel. Message names are reordered (async-no-reply, async-with-reply, sync) so the Decoder can infer the kind from the name value alone, and name() is now constexpr so send functions static-assert that the send function matches the message kind.
Before: After:
Sender Receiver Sender Receiver
├─ msg(replyID) ──► no handler ├─ msg(replyID) ──► !decoder.wasHandled()
│ handler pending until │◄─ CancelAsyncReply(id) ┤
│ conn invalidated │ handler(conn, nullptr decoder)
Significance
The IPC layer now guarantees that a reply completion handler runs even when the receiver is missing or ignores the message. That makes async replies usable for initialization and resource-management handshakes. Because the name-value ordering now drives message classification, it also changes how incoming messages are triaged on the boundary between a compromised renderer and privileged processes.
Audit directions
The new contracts shift risk onto every existing reply handler and every receive path outside generated dispatch. Narrow: confirm that CancelAsyncReply with an invalid ID is rejected as an invalid message, and that a compromised process cannot cancel another request's reply, or cancel the same ID twice or after a real reply. Wider: any existing reply handler that assumes a non-null decoder whenever the connection is valid is a null-deref or logic-error candidate. Every receiver that takes ownership of a reply outside the generated handler (deferred replies, replies completed on another queue, stream and out-of-stream paths in StreamServerConnection) must call markHandled(). A miss yields a spurious cancel after a real reply, or a cancel racing the real reply, which means double invocation and possible UAF of captured state. Classification: check messages at the name-range boundaries and out-of-range names, and whether a mismatched kind is rejected on the receive side and not only by send-side static asserts. IPCTestingAPI, WebProcessProxy::dispatchMessage, WebProcess::dispatchMessage, and sendAsyncReplyCancelIfNeeded each reimplement part of this logic. Callers of waitForAsyncReplyAndDispatchImmediately that assume a real reply arrived are worth a pass too.