OLD | NEW |
---|---|
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include "util/win/exception_handler_server.h" | 15 #include "util/win/exception_handler_server.h" |
16 | 16 |
17 #include <aclapi.h> | |
18 #include <sddl.h> | |
17 #include <string.h> | 19 #include <string.h> |
18 | 20 |
19 #include "base/logging.h" | 21 #include "base/logging.h" |
20 #include "base/numerics/safe_conversions.h" | 22 #include "base/numerics/safe_conversions.h" |
21 #include "base/rand_util.h" | 23 #include "base/rand_util.h" |
22 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
23 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
24 #include "minidump/minidump_file_writer.h" | 26 #include "minidump/minidump_file_writer.h" |
25 #include "snapshot/crashpad_info_client_options.h" | 27 #include "snapshot/crashpad_info_client_options.h" |
26 #include "snapshot/win/process_snapshot_win.h" | 28 #include "snapshot/win/process_snapshot_win.h" |
27 #include "util/file/file_writer.h" | 29 #include "util/file/file_writer.h" |
28 #include "util/misc/tri_state.h" | 30 #include "util/misc/tri_state.h" |
29 #include "util/misc/uuid.h" | 31 #include "util/misc/uuid.h" |
30 #include "util/win/get_function.h" | 32 #include "util/win/get_function.h" |
31 #include "util/win/handle.h" | 33 #include "util/win/handle.h" |
32 #include "util/win/registration_protocol_win.h" | 34 #include "util/win/registration_protocol_win.h" |
35 #include "util/win/scoped_local_free.h" | |
33 #include "util/win/xp_compat.h" | 36 #include "util/win/xp_compat.h" |
34 | 37 |
35 namespace crashpad { | 38 namespace crashpad { |
36 | 39 |
37 namespace { | 40 namespace { |
38 | 41 |
39 // We create two pipe instances, so that there's one listening while the | 42 // We create two pipe instances, so that there's one listening while the |
40 // PipeServiceProc is processing a registration. | 43 // PipeServiceProc is processing a registration. |
41 const size_t kPipeInstances = 2; | 44 const size_t kPipeInstances = 2; |
42 | 45 |
43 // Wraps CreateNamedPipe() to create a single named pipe instance. | 46 // Wraps CreateNamedPipe() to create a single named pipe instance. |
44 // | 47 // |
45 // If first_instance is true, the named pipe instance will be created with | 48 // If first_instance is true, the named pipe instance will be created with |
46 // FILE_FLAG_FIRST_PIPE_INSTANCE. This ensures that the the pipe name is not | 49 // FILE_FLAG_FIRST_PIPE_INSTANCE. This ensures that the the pipe name is not |
47 // already in use when created. | 50 // already in use when created. |
51 // | |
52 // The integrity level of the pipe is lowered so that it can be connected to by | |
53 // low integrity processes. | |
jschuh
2015/11/05 20:05:13
Should be "connected to by processes at any integr
scottmg
2015/11/05 20:15:30
Done.
| |
48 HANDLE CreateNamedPipeInstance(const std::wstring& pipe_name, | 54 HANDLE CreateNamedPipeInstance(const std::wstring& pipe_name, |
49 bool first_instance) { | 55 bool first_instance) { |
50 return CreateNamedPipe(pipe_name.c_str(), | 56 ScopedFileHandle pipe(CreateNamedPipe( |
51 PIPE_ACCESS_DUPLEX | | 57 pipe_name.c_str(), |
52 (first_instance ? FILE_FLAG_FIRST_PIPE_INSTANCE | 58 PIPE_ACCESS_DUPLEX | (first_instance ? FILE_FLAG_FIRST_PIPE_INSTANCE : 0), |
53 : 0), | 59 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, |
54 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, | 60 kPipeInstances, |
55 kPipeInstances, | 61 512, |
56 512, | 62 512, |
57 512, | 63 0, |
58 0, | 64 nullptr)); |
59 nullptr); | 65 if (!pipe.is_valid()) { |
66 PLOG(ERROR) << "CreateNamedPipe"; | |
67 return INVALID_HANDLE_VALUE; | |
68 } | |
69 | |
70 // We only need to set the integrity level on the first instance of the pipe. | |
Mark Mentovai
2015/11/05 20:08:01
Shouldn’t we still do this if we run crashpad_hand
scottmg
2015/11/05 20:15:30
Yes, we should, but don't we still in ExceptionHan
Mark Mentovai
2015/11/05 21:01:13
scottmg wrote:
| |
71 if (!first_instance) | |
72 return pipe.release(); | |
73 | |
74 // Lower the integrity of the pipe so that it can be connected to from low | |
75 // integrity processes (on Vista and later). | |
76 const DWORD version = GetVersion(); | |
77 const DWORD major_version = LOBYTE(LOWORD(version)); | |
78 const bool is_pre_vista = major_version < 6; | |
79 if (is_pre_vista) | |
80 return pipe.release(); | |
81 | |
82 // Mandatory Label, no ACE flags, no ObjectType, integrity level untrusted. | |
83 const wchar_t kSddl[] = L"S:(ML;;;;;S-1-16-0)"; | |
84 | |
85 PSECURITY_DESCRIPTOR sec_desc = nullptr; | |
Mark Mentovai
2015/11/05 20:08:01
SECURITY_DESCRIPTOR*, ACL*.
scottmg
2015/11/05 20:15:30
Done.
| |
86 | |
87 PACL sacl = nullptr; | |
88 if (!ConvertStringSecurityDescriptorToSecurityDescriptor( | |
89 kSddl, SDDL_REVISION, &sec_desc, nullptr)) { | |
90 PLOG(ERROR) << "ConvertStringSecurityDescriptorToSecurityDescriptorW"; | |
Mark Mentovai
2015/11/05 20:08:01
No W on the end.
scottmg
2015/11/05 20:15:30
Done.
| |
91 return INVALID_HANDLE_VALUE; | |
92 } | |
93 | |
94 // Take ownership of the allocated SECURITY_DESCRIPTOR. | |
95 ScopedLocalFree scoped_sec_desc(sec_desc); | |
96 | |
97 BOOL sacl_present = FALSE; | |
98 BOOL sacl_defaulted = FALSE; | |
99 if (!GetSecurityDescriptorSacl( | |
100 sec_desc, &sacl_present, &sacl, &sacl_defaulted)) { | |
101 PLOG(ERROR) << "GetSecurityDescriptorSacl"; | |
102 return INVALID_HANDLE_VALUE; | |
103 } | |
104 | |
105 DWORD error = SetSecurityInfo(pipe.get(), | |
106 SE_KERNEL_OBJECT, | |
107 LABEL_SECURITY_INFORMATION, | |
108 nullptr, | |
109 nullptr, | |
110 nullptr, | |
111 sacl); | |
112 if (error != ERROR_SUCCESS) { | |
113 LOG(ERROR) << "SetSecurityInfo: " | |
114 << logging::SystemErrorCodeToString(error); | |
115 return INVALID_HANDLE_VALUE; | |
116 } | |
117 | |
118 return pipe.release(); | |
60 } | 119 } |
61 | 120 |
62 decltype(GetNamedPipeClientProcessId)* GetNamedPipeClientProcessIdFunction() { | 121 decltype(GetNamedPipeClientProcessId)* GetNamedPipeClientProcessIdFunction() { |
63 static const auto get_named_pipe_client_process_id = | 122 static const auto get_named_pipe_client_process_id = |
64 GET_FUNCTION(L"kernel32.dll", ::GetNamedPipeClientProcessId); | 123 GET_FUNCTION(L"kernel32.dll", ::GetNamedPipeClientProcessId); |
65 return get_named_pipe_client_process_id; | 124 return get_named_pipe_client_process_id; |
66 } | 125 } |
67 | 126 |
68 HANDLE DuplicateEvent(HANDLE process, HANDLE event) { | 127 HANDLE DuplicateEvent(HANDLE process, HANDLE event) { |
69 HANDLE handle; | 128 HANDLE handle; |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 void __stdcall ExceptionHandlerServer::OnProcessEnd(void* ctx, BOOLEAN) { | 620 void __stdcall ExceptionHandlerServer::OnProcessEnd(void* ctx, BOOLEAN) { |
562 // This function is executed on the thread pool. | 621 // This function is executed on the thread pool. |
563 internal::ClientData* client = reinterpret_cast<internal::ClientData*>(ctx); | 622 internal::ClientData* client = reinterpret_cast<internal::ClientData*>(ctx); |
564 base::AutoLock lock(*client->lock()); | 623 base::AutoLock lock(*client->lock()); |
565 | 624 |
566 // Post back to the main thread to have it delete this client record. | 625 // Post back to the main thread to have it delete this client record. |
567 PostQueuedCompletionStatus(client->port(), 0, ULONG_PTR(client), nullptr); | 626 PostQueuedCompletionStatus(client->port(), 0, ULONG_PTR(client), nullptr); |
568 } | 627 } |
569 | 628 |
570 } // namespace crashpad | 629 } // namespace crashpad |
OLD | NEW |