Issue metadata
Sign in to add a comment
|
Security: mojo: Unchecked ports message payload lengths leading to buffer overflows and uafs |
||||||||||||||||||||
Issue description
It looks like ports message payloads are not checked in several places:
MessagePipeDispatcher::ReadMessage():
int rv = node_controller_->node()->GetMessageIf(
port_,
[read_any_size, num_bytes, num_handles, &no_space, &may_discard](
const ports::Message& next_message) {
const PortsMessage& message =
static_cast<const PortsMessage&>(next_message);
DCHECK_GE(message.num_payload_bytes(), sizeof(MessageHeader));
const MessageHeader* header =
static_cast<const MessageHeader*>(message.payload_bytes());
DCHECK_LE(header->header_size, message.num_payload_bytes());
The DCHECKS should not be DCHECKS.
It looks like there are similar issues in:
void DataPipeConsumerDispatcher::UpdateSignalsStateNoLock() {
...
ports::ScopedMessage message;
do {
int rv = node_controller_->node()->GetMessageIf(control_port_, nullptr,
&message);
if (rv != ports::OK)
peer_closed_ = true;
if (message) {
const DataPipeControlMessage* m =
static_cast<const DataPipeControlMessage*>(
message->payload_bytes());
and also in DataPipeProducerDispatcher::UpdateSignalsStateNoLock().
I've attached a patch to set incoming ports message's payload size to 1 in channel_posix, which I used to reproduce buffer overflows:
==29923==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x607000003394 at pc 0x7f48721873f0 bp
READ of size 4 at 0x607000003394 thread T0 (chrome)
#0 0x7f48721873ef in operator() out/Default/../../mojo/edk/system/message_pipe_dispatcher.cc:202:21
#1 0x7f48721873ef in __invoke<(lambda at ../../mojo/edk/system/message_pipe_dispatcher.cc:189:7) &, c
#2 0x7f48721873ef in __call<(lambda at ../../mojo/edk/system/message_pipe_dispatcher.cc:189:7) &, con
#3 0x7f48721873ef in std::__1::__function::__func<mojo::edk::MessagePipeDispatcher::ReadMessage(std::
#4 0x7f48721d19f2 in operator() out/Default/../../buildtools/third_party/libc++/trunk/include/functio
#5 0x7f48721d19f2 in mojo::edk::ports::MessageQueue::GetNextMessageIf(std::__1::function<bool (mojo::
#6 0x7f48721d86f1 in mojo::edk::ports::Node::GetMessageIf(mojo::edk::ports::PortRef const&, std::__1:
#7 0x7f4872184776 in mojo::edk::MessagePipeDispatcher::ReadMessage(std::__1::unique_ptr<mojo::edk::Me
#8 0x7f487216ccce in mojo::edk::Core::ReadMessageNew(unsigned int, unsigned long*, unsigned int*, uns
#9 0x7f48721c73bb in MojoReadMessageNew out/Default/../../mojo/edk/embedder/entrypoints.cc:134:10
Also, while running Chrome with this patch, I also found that a use-after-free can be triggered during NodeChannel::DropPeer() (output attached as drop_peer_uaf.txt):
NodeChannel::DropPeer() takes a ports::NodeName as a reference. However, it's possible that this is a reference of NodeChannel's |remote_node_name_|. This means that:
void NodeController::DropPeer(const ports::NodeName& name) {
DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
{
base::AutoLock lock(peers_lock_);
auto it = peers_.find(name);
if (it != peers_.end()) {
ports::NodeName peer = it->first;
peers_.erase(it);
DVLOG(1) << "Dropped peer " << peer;
}
pending_peer_messages_.erase(name);
pending_children_.erase(name);
RecordPeerCount(peers_.size());
RecordPendingChildCount(pending_children_.size());
}
node_->LostConnectionToNode(name);
}
The peers_.erase(it) here can result in the NodeChannel being freed, and thus the |name| reference left pointing to freed memory. (|peers| is a std::unordered_map<ports::NodeName, scoped_refptr<NodeChannel>>),
,
May 23 2016
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/99a83d5bc1df0c4d6d660dedf45c9b0e14a9df3f commit 99a83d5bc1df0c4d6d660dedf45c9b0e14a9df3f Author: rockot <rockot@chromium.org> Date: Mon May 23 18:41:59 2016 [mojo-edk] Add some buffer checks and fix UAF on NodeChannel Adds message sanity checks at the dispatcher layer for message and data pipes. Also eliminates potential UAFs on NodeChannel by ensuring it stays alive through any delegate calls which might have otherwise deleted it. BUG= 613698 Review-Url: https://codereview.chromium.org/2004763002 Cr-Commit-Position: refs/heads/master@{#395373} [modify] https://crrev.com/99a83d5bc1df0c4d6d660dedf45c9b0e14a9df3f/mojo/edk/system/data_pipe_consumer_dispatcher.cc [modify] https://crrev.com/99a83d5bc1df0c4d6d660dedf45c9b0e14a9df3f/mojo/edk/system/data_pipe_producer_dispatcher.cc [modify] https://crrev.com/99a83d5bc1df0c4d6d660dedf45c9b0e14a9df3f/mojo/edk/system/message_pipe_dispatcher.cc [modify] https://crrev.com/99a83d5bc1df0c4d6d660dedf45c9b0e14a9df3f/mojo/edk/system/node_channel.cc
,
May 23 2016
Thanks for fixing this, rockot! Marking as fixed.
,
May 23 2016
Adding Merge-Triage label for tracking purposes. Once your fix had sufficient bake time (on canary, dev as appropriate), please nominate your fix for merge by adding the Merge-Request-XX label, where XX is the Chrome milestone. When your merge is approved by the release manager, please start merging with higher milestone label first. Make sure to re-request merge for every milestone in the label list. You can get branch information on omahaproxy.appspot.com. - Your friendly ClusterFuzz
,
May 24 2016
,
May 24 2016
This is a security fix affecting all platforms. It's out in current canaries and is safe to merge.
,
May 24 2016
Your change meets the bar and is auto-approved for M52 (branch: 2743)
,
May 24 2016
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/d056d244f7068902a46b7e997eb28015fd2ccda4 commit d056d244f7068902a46b7e997eb28015fd2ccda4 Author: Ken Rockot <rockot@chromium.org> Date: Tue May 24 17:52:19 2016 [mojo-edk] Add some buffer checks and fix UAF on NodeChannel Adds message sanity checks at the dispatcher layer for message and data pipes. Also eliminates potential UAFs on NodeChannel by ensuring it stays alive through any delegate calls which might have otherwise deleted it. BUG= 613698 Review-Url: https://codereview.chromium.org/2004763002 Cr-Commit-Position: refs/heads/master@{#395373} (cherry picked from commit 99a83d5bc1df0c4d6d660dedf45c9b0e14a9df3f) Review URL: https://codereview.chromium.org/2007943003 . Cr-Commit-Position: refs/branch-heads/2743@{#37} Cr-Branched-From: 2b3ae3b8090361f8af5a611712fc1a5ab2de53cb-refs/heads/master@{#394939} [modify] https://crrev.com/d056d244f7068902a46b7e997eb28015fd2ccda4/mojo/edk/system/data_pipe_consumer_dispatcher.cc [modify] https://crrev.com/d056d244f7068902a46b7e997eb28015fd2ccda4/mojo/edk/system/data_pipe_producer_dispatcher.cc [modify] https://crrev.com/d056d244f7068902a46b7e997eb28015fd2ccda4/mojo/edk/system/message_pipe_dispatcher.cc [modify] https://crrev.com/d056d244f7068902a46b7e997eb28015fd2ccda4/mojo/edk/system/node_channel.cc
,
May 31 2016
Requesting merge for M51 (High severity, affects stable build).
,
May 31 2016
[Automated comment] Request affecting a post-stable build (M51), manual review required.
,
Jun 1 2016
,
Jun 3 2016
Approving merge to M51 branch 2704 based on comment #6 and comment #9. Please merge ASAP. Thank you.
,
Jun 3 2016
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/76fe408535f6fb2323f366fd2cc1d4d925863a72 commit 76fe408535f6fb2323f366fd2cc1d4d925863a72 Author: Ken Rockot <rockot@chromium.org> Date: Fri Jun 03 19:04:03 2016 [mojo-edk] Add some buffer checks and fix UAF on NodeChannel Adds message sanity checks at the dispatcher layer for message and data pipes. Also eliminates potential UAFs on NodeChannel by ensuring it stays alive through any delegate calls which might have otherwise deleted it. BUG= 613698 Review-Url: https://codereview.chromium.org/2004763002 Cr-Commit-Position: refs/heads/master@{#395373} (cherry picked from commit 99a83d5bc1df0c4d6d660dedf45c9b0e14a9df3f) Review URL: https://codereview.chromium.org/2034183002 . Cr-Commit-Position: refs/branch-heads/2704@{#703} Cr-Branched-From: 6e53600def8f60d8c632fadc70d7c1939ccea347-refs/heads/master@{#386251} [modify] https://crrev.com/76fe408535f6fb2323f366fd2cc1d4d925863a72/mojo/edk/system/data_pipe_consumer_dispatcher.cc [modify] https://crrev.com/76fe408535f6fb2323f366fd2cc1d4d925863a72/mojo/edk/system/data_pipe_producer_dispatcher.cc [modify] https://crrev.com/76fe408535f6fb2323f366fd2cc1d4d925863a72/mojo/edk/system/message_pipe_dispatcher.cc [modify] https://crrev.com/76fe408535f6fb2323f366fd2cc1d4d925863a72/mojo/edk/system/node_channel.cc
,
Jun 3 2016
,
Jun 6 2016
Noting in next M51 release notes.
,
Aug 30 2016
This bug has been closed for more than 14 weeks. Removing security view restrictions. For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
,
Oct 1 2016
This bug has been closed for more than 14 weeks. Removing security view restrictions. For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
,
Oct 2 2016
This bug has been closed for more than 14 weeks. Removing security view restrictions. For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
,
Oct 2 2016
,
Jul 28
|
|||||||||||||||||||||
►
Sign in to add a comment |
|||||||||||||||||||||
Comment 1 by ClusterFuzz
, May 21 2016