Update V8 to version 4.3.37.
[chromium-blink-merge.git] / sandbox / win / src / named_pipe_dispatcher.cc
blob5527319833cb4e818376e66452c1cd2939dfc522
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "sandbox/win/src/named_pipe_dispatcher.h"
7 #include "base/basictypes.h"
8 #include "base/strings/string_split.h"
10 #include "sandbox/win/src/crosscall_client.h"
11 #include "sandbox/win/src/interception.h"
12 #include "sandbox/win/src/interceptors.h"
13 #include "sandbox/win/src/ipc_tags.h"
14 #include "sandbox/win/src/named_pipe_interception.h"
15 #include "sandbox/win/src/named_pipe_policy.h"
16 #include "sandbox/win/src/policy_broker.h"
17 #include "sandbox/win/src/policy_params.h"
18 #include "sandbox/win/src/sandbox.h"
21 namespace sandbox {
23 NamedPipeDispatcher::NamedPipeDispatcher(PolicyBase* policy_base)
24 : policy_base_(policy_base) {
25 static const IPCCall create_params = {
26 {IPC_CREATENAMEDPIPEW_TAG, WCHAR_TYPE, UINT32_TYPE, UINT32_TYPE,
27 UINT32_TYPE, UINT32_TYPE, UINT32_TYPE, UINT32_TYPE},
28 reinterpret_cast<CallbackGeneric>(&NamedPipeDispatcher::CreateNamedPipe)
31 ipc_calls_.push_back(create_params);
34 bool NamedPipeDispatcher::SetupService(InterceptionManager* manager,
35 int service) {
36 if (IPC_CREATENAMEDPIPEW_TAG == service)
37 return INTERCEPT_EAT(manager, kKerneldllName, CreateNamedPipeW,
38 CREATE_NAMED_PIPE_ID, 36);
40 return false;
43 bool NamedPipeDispatcher::CreateNamedPipe(IPCInfo* ipc,
44 base::string16* name,
45 uint32 open_mode,
46 uint32 pipe_mode,
47 uint32 max_instances,
48 uint32 out_buffer_size,
49 uint32 in_buffer_size,
50 uint32 default_timeout) {
51 ipc->return_info.win32_result = ERROR_ACCESS_DENIED;
52 ipc->return_info.handle = INVALID_HANDLE_VALUE;
54 std::vector<base::string16> paths;
55 std::vector<base::string16> innerpaths;
56 base::SplitString(*name, '/', &paths);
58 for (std::vector<base::string16>::const_iterator iter = paths.begin();
59 iter != paths.end(); ++iter) {
60 base::SplitString(*iter, '\\', &innerpaths);
61 for (std::vector<base::string16>::const_iterator iter2 = innerpaths.begin();
62 iter2 != innerpaths.end(); ++iter2) {
63 if (*iter2 == L"..")
64 return true;
68 const wchar_t* pipe_name = name->c_str();
69 CountedParameterSet<NameBased> params;
70 params[NameBased::NAME] = ParamPickerMake(pipe_name);
72 EvalResult eval = policy_base_->EvalPolicy(IPC_CREATENAMEDPIPEW_TAG,
73 params.GetBase());
75 // "For file I/O, the "\\?\" prefix to a path string tells the Windows APIs to
76 // disable all string parsing and to send the string that follows it straight
77 // to the file system."
78 // http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx
79 // This ensures even if there is a path traversal in the pipe name, and it is
80 // able to get past the checks above, it will still not be allowed to escape
81 // our whitelisted namespace.
82 if (name->compare(0, 4, L"\\\\.\\") == 0)
83 name->replace(0, 4, L"\\\\\?\\");
85 HANDLE pipe;
86 DWORD ret = NamedPipePolicy::CreateNamedPipeAction(eval, *ipc->client_info,
87 *name, open_mode,
88 pipe_mode, max_instances,
89 out_buffer_size,
90 in_buffer_size,
91 default_timeout, &pipe);
93 ipc->return_info.win32_result = ret;
94 ipc->return_info.handle = pipe;
95 return true;
98 } // namespace sandbox