New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 613698 link

Starred by 3 users

Issue metadata

Status: Fixed
Owner:
please use my google.com address
Closed: May 2016
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 1
Type: Bug-Security



Sign in to add a comment

Security: mojo: Unchecked ports message payload lengths leading to buffer overflows and uafs

Project Member Reported by och...@chromium.org, May 20 2016

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>>), 
 
blah.patch
1.7 KB Download
drop_peer_uaf.txt
16.4 KB View Download
Project Member

Comment 1 by ClusterFuzz, May 21 2016

Status: Assigned (was: Unconfirmed)
Project Member

Comment 2 by bugdroid1@chromium.org, 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

Comment 3 by och...@chromium.org, May 23 2016

Labels: Security_Severity-High Security_Impact-Stable
Status: Fixed (was: Assigned)
Thanks for fixing this, rockot! Marking as fixed.
Project Member

Comment 4 by ClusterFuzz, May 23 2016

Labels: Merge-Triage M-51 M-52
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
Project Member

Comment 5 by sheriffbot@chromium.org, May 24 2016

Labels: -Restrict-View-SecurityTeam Restrict-View-SecurityNotify

Comment 6 by roc...@chromium.org, May 24 2016

Labels: Merge-Request-52
This is a security fix affecting all platforms. It's out in current canaries and is safe to merge.

Comment 7 by tin...@google.com, May 24 2016

Labels: -Merge-Request-52 Merge-Approved-52 Hotlist-Merge-Approved
Your change meets the bar and is auto-approved for M52 (branch: 2743)
Project Member

Comment 8 by bugdroid1@chromium.org, May 24 2016

Labels: -merge-approved-52 merge-merged-2743
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

Labels: -Merge-Triage Merge-Request-51
Requesting merge for M51 (High severity, affects stable build).

Comment 10 by tin...@google.com, May 31 2016

Labels: -Merge-Request-51 Merge-Review-51 Hotlist-Merge-Review
[Automated comment] Request affecting a post-stable build (M51), manual review required.
Labels: OS-All
Labels: -Merge-Review-51 Merge-Approved-51
Approving merge to M51 branch 2704 based on comment #6 and comment #9. Please merge ASAP. Thank you.
Project Member

Comment 13 by bugdroid1@chromium.org, Jun 3 2016

Labels: -merge-approved-51 merge-merged-2704
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

Labels: Release-2-M51
Labels: -Release-2-M51 Release-3-M51
Noting in next M51 release notes.
Project Member

Comment 16 by sheriffbot@chromium.org, Aug 30 2016

Labels: -Restrict-View-SecurityNotify
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
Project Member

Comment 17 by sheriffbot@chromium.org, 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
Project Member

Comment 18 by sheriffbot@chromium.org, 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
Labels: allpublic
Project Member

Comment 20 by sheriffbot@chromium.org, Jul 28

Labels: Pri-1

Sign in to add a comment