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

Unified Diff: sandbox/win/src/named_pipe_dispatcher.cc

Issue 145553007: Correctly test for canonicalized path in the CreateNamedPipe policy engine. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add specific traversal checks. Move canonicalization test to in-process. Created 6 years, 11 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 | sandbox/win/src/named_pipe_policy_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/win/src/named_pipe_dispatcher.cc
diff --git a/sandbox/win/src/named_pipe_dispatcher.cc b/sandbox/win/src/named_pipe_dispatcher.cc
index 54b3162bfa57fa13baa27b003b17fb03fa3f1b7a..fdd7398779d33c1194f8343e64cc07b86acdd5f8 100644
--- a/sandbox/win/src/named_pipe_dispatcher.cc
+++ b/sandbox/win/src/named_pipe_dispatcher.cc
@@ -5,6 +5,7 @@
#include "sandbox/win/src/named_pipe_dispatcher.h"
#include "base/basictypes.h"
+#include "base/strings/string_split.h"
#include "sandbox/win/src/crosscall_client.h"
#include "sandbox/win/src/interception.h"
@@ -43,6 +44,28 @@ bool NamedPipeDispatcher::CreateNamedPipe(
IPCInfo* ipc, base::string16* name, DWORD open_mode, DWORD pipe_mode,
DWORD max_instances, DWORD out_buffer_size, DWORD in_buffer_size,
DWORD default_timeout) {
+ ipc->return_info.win32_result = ERROR_ACCESS_DENIED;
+ ipc->return_info.handle = INVALID_HANDLE_VALUE;
jschuh 2014/01/27 20:29:47 Never put INVALID_HANDLE_VALUE in anything that ma
Will Harris 2014/01/27 23:47:18 Done.
+
+ std::vector<base::string16> paths;
+ base::SplitString(*name, '\\', &paths);
+
+ for (std::vector<base::string16>::const_iterator iter = paths.begin();
+ iter != paths.end(); ++iter) {
+ if (*iter == L"..")
+ return true;
+ }
+
+ // Windows happily accepts / as well as \ once into the pipe namespace, so we
+ // check for this as well.
+ base::SplitString(*name, '/', &paths);
+
+ for (std::vector<base::string16>::const_iterator iter = paths.begin();
jschuh 2014/01/27 20:29:47 Don't you want to nest this inside the above loop,
Will Harris 2014/01/27 23:47:18 Done.
+ iter != paths.end(); ++iter) {
+ if (*iter == L"..")
+ return true;
+ }
+
const wchar_t* pipe_name = name->c_str();
CountedParameterSet<NameBased> params;
params[NameBased::NAME] = ParamPickerMake(pipe_name);
@@ -50,6 +73,16 @@ bool NamedPipeDispatcher::CreateNamedPipe(
EvalResult eval = policy_base_->EvalPolicy(IPC_CREATENAMEDPIPEW_TAG,
params.GetBase());
+ // "For file I/O, the "\\?\" prefix to a path string tells the Windows APIs to
+ // disable all string parsing and to send the string that follows it straight
+ // to the file system."
+ // http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx
+ // This ensures even if there is a path traversal in the pipe name, and it is
+ // able to get past the checks above, it will still not be allowed to escape
+ // our whitelisted namespace.
+ if (name->compare(0, 4, L"\\\\.\\") == 0)
+ name->replace(0, 4, L"\\\\\?\\");
+
HANDLE pipe;
DWORD ret = NamedPipePolicy::CreateNamedPipeAction(eval, *ipc->client_info,
*name, open_mode,
« no previous file with comments | « no previous file | sandbox/win/src/named_pipe_policy_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698