Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Unified Diff: dbus/message.cc

Issue 10382021: dbus: revamp fd passing for i/o restrictions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dbus/message.cc
diff --git a/dbus/message.cc b/dbus/message.cc
index d52591217e47bedadb04afcaf57dfcc5b3fcb435..5bbfafb5325bed1f51df5b64cb2c202f18b7a501 100644
--- a/dbus/message.cc
+++ b/dbus/message.cc
@@ -11,6 +11,7 @@
#include "base/logging.h"
#include "base/platform_file.h"
#include "base/stringprintf.h"
+#include "base/threading/thread_restrictions.h"
#include "dbus/object_path.h"
#include "third_party/protobuf/src/google/protobuf/message_lite.h"
@@ -37,6 +38,17 @@ static void AppendUint32Header(const std::string& header_name,
}
}
+// Checks if |fd| is suitable for sending/receiving. We disallow
+// directories to avoid potential sandbox escapes.
+static bool CheckFileDescriptor(int fd) {
+ // NB: bypass i/o restrictions, current uses will not block
+ bool prev = base::ThreadRestrictions::SetIOAllowed(true);
satorux1 2012/05/04 22:31:22 ThreadRestrictions::ScopedAllowIO would be simpler
+ base::PlatformFileInfo info;
+ bool ok = base::GetPlatformFileInfo(fd, &info);
+ base::ThreadRestrictions::SetIOAllowed(prev);
+ return (ok && !info.is_directory);
+}
+
} // namespace
namespace dbus {
@@ -691,10 +703,8 @@ void MessageWriter::AppendVariantOfBasic(int dbus_type, const void* value) {
void MessageWriter::AppendFileDescriptor(const FileDescriptor& value) {
CHECK(kDBusTypeUnixFdIsSupported);
- base::PlatformFileInfo info;
int fd = value.value();
- bool ok = base::GetPlatformFileInfo(fd, &info);
- if (!ok || info.is_directory) {
+ if (!CheckFileDescriptor(fd)) {
satorux1 2012/05/04 22:31:22 Maybe this wasn't the right place to validate this
// NB: sending a directory potentially enables sandbox escape
LOG(FATAL) << "Attempt to pass invalid file descriptor";
}
@@ -968,9 +978,7 @@ bool MessageReader::PopFileDescriptor(FileDescriptor* value) {
if (!success)
return false;
- base::PlatformFileInfo info;
- bool ok = base::GetPlatformFileInfo(fd, &info);
- if (!ok || info.is_directory) {
+ if (!CheckFileDescriptor(fd)) {
base::ClosePlatformFile(fd);
// NB: receiving a directory potentially enables sandbox escape
LOG(FATAL) << "Attempt to receive invalid file descriptor";
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698