Skip to content

Commit

Permalink
[mojo-core] Validate data pipe endpoint metadata
Browse files Browse the repository at this point in the history
Ensures that we don't blindly trust specified buffer size and offset
metadata when deserializing data pipe consumer and producer handles.

Bug: 877182
Change-Id: I30f3eceafb5cee06284c2714d08357ef911d6fd9
Reviewed-on: https://chromium-review.googlesource.com/1192922
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Ken Rockot <rockot@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586704}
  • Loading branch information
krockot authored and Commit Bot committed Aug 28, 2018
1 parent f21eb69 commit 66e24a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion mojo/core/data_pipe_consumer_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@ DataPipeConsumerDispatcher::Deserialize(const void* data,

const SerializedState* state = static_cast<const SerializedState*>(data);
if (!state->options.capacity_num_bytes || !state->options.element_num_bytes ||
state->options.capacity_num_bytes < state->options.element_num_bytes) {
state->options.capacity_num_bytes < state->options.element_num_bytes ||
state->read_offset >= state->options.capacity_num_bytes ||
state->bytes_available > state->options.capacity_num_bytes) {
return nullptr;
}

Expand Down Expand Up @@ -408,6 +410,10 @@ DataPipeConsumerDispatcher::Deserialize(const void* data,
dispatcher->peer_closed_ = state->flags & kFlagPeerClosed;
if (!dispatcher->InitializeNoLock())
return nullptr;
if (state->options.capacity_num_bytes >
dispatcher->ring_buffer_mapping_.mapped_size()) {
return nullptr;
}
dispatcher->UpdateSignalsStateNoLock();
}

Expand Down
8 changes: 7 additions & 1 deletion mojo/core/data_pipe_producer_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,9 @@ DataPipeProducerDispatcher::Deserialize(const void* data,

const SerializedState* state = static_cast<const SerializedState*>(data);
if (!state->options.capacity_num_bytes || !state->options.element_num_bytes ||
state->options.capacity_num_bytes < state->options.element_num_bytes) {
state->options.capacity_num_bytes < state->options.element_num_bytes ||
state->write_offset >= state->options.capacity_num_bytes ||
state->available_capacity > state->options.capacity_num_bytes) {
return nullptr;
}

Expand Down Expand Up @@ -368,6 +370,10 @@ DataPipeProducerDispatcher::Deserialize(const void* data,
dispatcher->peer_closed_ = state->flags & kFlagPeerClosed;
if (!dispatcher->InitializeNoLock())
return nullptr;
if (state->options.capacity_num_bytes >
dispatcher->ring_buffer_mapping_.mapped_size()) {
return nullptr;
}
dispatcher->UpdateSignalsStateNoLock();
}

Expand Down

0 comments on commit 66e24a8

Please sign in to comment.