summaryrefslogtreecommitdiff
path: root/chromium/sandbox
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-03-08 13:07:32 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-03-08 13:40:10 +0000
commit818d9aed569afd192f6d4f6d9b28b72912df8b93 (patch)
treefa30cbdffa3e8fdc09dbbe37ffc0a721b40fced1 /chromium/sandbox
parent66a2147d838e293f4a5db7711c8eba4e6faaaf0f (diff)
downloadqtwebengine-chromium-818d9aed569afd192f6d4f6d9b28b72912df8b93.tar.gz
BASELINE: Update Chromium to 65.0.3325.151
Change-Id: I3c71dd500483eb29491ac3eee4123714dda52da9 Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/sandbox')
-rw-r--r--chromium/sandbox/mac/seatbelt_exec.cc105
-rw-r--r--chromium/sandbox/mac/seatbelt_exec.h2
2 files changed, 87 insertions, 20 deletions
diff --git a/chromium/sandbox/mac/seatbelt_exec.cc b/chromium/sandbox/mac/seatbelt_exec.cc
index 53a5e7901ae..df8167cf50d 100644
--- a/chromium/sandbox/mac/seatbelt_exec.cc
+++ b/chromium/sandbox/mac/seatbelt_exec.cc
@@ -5,6 +5,7 @@
#include "sandbox/mac/seatbelt_exec.h"
#include <fcntl.h>
+#include <inttypes.h>
#include <stdarg.h>
#include <stdio.h>
#include <sys/socket.h>
@@ -20,6 +21,58 @@
namespace sandbox {
+namespace {
+
+struct ReadTraits {
+ using BufferType = uint8_t*;
+ static constexpr char kNameString[] = "read";
+ static ssize_t Operate(int fd, BufferType buffer, size_t size) {
+ return read(fd, buffer, size);
+ }
+};
+constexpr char ReadTraits::kNameString[];
+
+struct WriteTraits {
+ using BufferType = const uint8_t*;
+ static constexpr char kNameString[] = "write";
+ static ssize_t Operate(int fd, BufferType buffer, size_t size) {
+ return write(fd, buffer, size);
+ }
+};
+constexpr char WriteTraits::kNameString[];
+
+template <typename Traits>
+bool ReadOrWrite(int fd,
+ const typename Traits::BufferType buffer,
+ const size_t size) {
+ if (size > std::numeric_limits<ssize_t>::max()) {
+ logging::Error("request size is greater than ssize_t::max");
+ return false;
+ }
+
+ ssize_t bytes_to_transact = static_cast<ssize_t>(size);
+
+ while (bytes_to_transact > 0) {
+ ssize_t offset = size - bytes_to_transact;
+ ssize_t transacted_bytes =
+ HANDLE_EINTR(Traits::Operate(fd, buffer + offset, bytes_to_transact));
+ if (transacted_bytes < 0) {
+ if (errno == EAGAIN) {
+ sched_yield();
+ continue;
+ }
+ logging::PError("%s failed", Traits::kNameString);
+ return false;
+ }
+
+ bytes_to_transact -= transacted_bytes;
+ }
+
+ return true;
+}
+
+} // namespace
+
SeatbeltExecClient::SeatbeltExecClient() {
if (pipe(pipe_) != 0)
logging::PFatal("SeatbeltExecClient: pipe failed");
@@ -59,29 +112,41 @@ void SeatbeltExecClient::SetProfile(const std::string& policy) {
int SeatbeltExecClient::SendProfileAndGetFD() {
std::string serialized_protobuf;
- if (!policy_.SerializeToString(&serialized_protobuf))
+ if (!policy_.SerializeToString(&serialized_protobuf)) {
+ logging::Error("SeatbeltExecClient: Serializing the profile failed.");
return -1;
+ }
- if (!WriteString(&serialized_protobuf))
+ if (!WriteString(serialized_protobuf)) {
+ logging::Error(
+ "SeatbeltExecClient: Writing the serialized profile failed.");
return -1;
+ }
IGNORE_EINTR(close(pipe_[1]));
pipe_[1] = -1;
+ if (pipe_[0] < 0)
+ logging::Error("SeatbeltExecClient: The pipe returned an invalid fd.");
+
return pipe_[0];
}
-bool SeatbeltExecClient::WriteString(std::string* str) {
- struct iovec iov[1];
- iov[0].iov_base = &(*str)[0];
- iov[0].iov_len = str->size();
+bool SeatbeltExecClient::WriteString(const std::string& str) {
+ uint64_t str_len = static_cast<uint64_t>(str.size());
+ if (!ReadOrWrite<WriteTraits>(pipe_[1], reinterpret_cast<uint8_t*>(&str_len),
+ sizeof(str_len))) {
+ logging::Error("SeatbeltExecClient: write buffer length failed.");
+ return false;
+ }
- ssize_t written = HANDLE_EINTR(writev(pipe_[1], iov, arraysize(iov)));
- if (written < 0) {
- logging::PError("SeatbeltExecClient: writev failed");
+ if (!ReadOrWrite<WriteTraits>(
+ pipe_[1], reinterpret_cast<const uint8_t*>(&str[0]), str_len)) {
+ logging::Error("SeatbeltExecClient: write buffer failed.");
return false;
}
- return static_cast<uint64_t>(written) == str->size();
+
+ return true;
}
SeatbeltExecServer::SeatbeltExecServer(int fd) : fd_(fd), extra_params_() {}
@@ -130,19 +195,21 @@ bool SeatbeltExecServer::ApplySandboxProfile(const mac::SandboxPolicy& policy) {
}
bool SeatbeltExecServer::ReadString(std::string* str) {
- // 4 pages of memory is enough to hold the sandbox profiles.
- std::vector<char> buffer(4096 * 4, '\0');
+ uint64_t buf_len = 0;
+ if (!ReadOrWrite<ReadTraits>(fd_, reinterpret_cast<uint8_t*>(&buf_len),
+ sizeof(buf_len))) {
+ logging::Error("SeatbeltExecServer: failed to read buffer length.");
+ return false;
+ }
- struct iovec iov[1];
- iov[0].iov_base = buffer.data();
- iov[0].iov_len = buffer.size();
+ str->resize(buf_len);
- ssize_t read_length = HANDLE_EINTR(readv(fd_, iov, arraysize(iov)));
- if (read_length < 0) {
- logging::PError("SeatbeltExecServer: readv failed");
+ if (!ReadOrWrite<ReadTraits>(fd_, reinterpret_cast<uint8_t*>(&(*str)[0]),
+ buf_len)) {
+ logging::Error("SeatbeltExecServer: failed to read buffer.");
return false;
}
- str->assign(buffer.data());
+
return true;
}
diff --git a/chromium/sandbox/mac/seatbelt_exec.h b/chromium/sandbox/mac/seatbelt_exec.h
index 08ad5c67787..3366d14e65f 100644
--- a/chromium/sandbox/mac/seatbelt_exec.h
+++ b/chromium/sandbox/mac/seatbelt_exec.h
@@ -45,7 +45,7 @@ class SEATBELT_EXPORT SeatbeltExecClient {
private:
// This writes a string (the serialized protobuf) to the |pipe_|.
- bool WriteString(std::string* str);
+ bool WriteString(const std::string& str);
// This is the protobuf which contains the sandbox profile and parameters,
// and is serialized and sent to the other process.