OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 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, |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include <string> | 21 #include <string> |
22 | 22 |
23 #include "base/auto_reset.h" | 23 #include "base/auto_reset.h" |
24 #include "base/logging.h" | 24 #include "base/logging.h" |
25 #include "base/mac/scoped_mach_port.h" | 25 #include "base/mac/scoped_mach_port.h" |
26 #include "base/memory/scoped_ptr.h" | 26 #include "base/memory/scoped_ptr.h" |
27 #include "base/rand_util.h" | 27 #include "base/rand_util.h" |
28 #include "gtest/gtest.h" | 28 #include "gtest/gtest.h" |
29 #include "util/file/file_io.h" | 29 #include "util/file/file_io.h" |
30 #include "util/mach/mach_extensions.h" | 30 #include "util/mach/mach_extensions.h" |
| 31 #include "util/mach/mach_message.h" |
31 #include "util/misc/scoped_forbid_return.h" | 32 #include "util/misc/scoped_forbid_return.h" |
32 #include "util/test/errors.h" | 33 #include "util/test/errors.h" |
33 #include "util/test/mac/mach_errors.h" | 34 #include "util/test/mac/mach_errors.h" |
34 | 35 |
35 namespace { | 36 namespace { |
36 | 37 |
37 // The “hello” message contains a send right to the child process’ task port. | 38 // The “hello” message contains a send right to the child process’ task port. |
38 struct SendHelloMessage : public mach_msg_base_t { | 39 struct SendHelloMessage : public mach_msg_base_t { |
39 mach_msg_port_descriptor_t port_descriptor; | 40 mach_msg_port_descriptor_t port_descriptor; |
40 }; | 41 }; |
41 | 42 |
42 struct ReceiveHelloMessage : public SendHelloMessage { | 43 struct ReceiveHelloMessage : public SendHelloMessage { |
43 mach_msg_audit_trailer_t audit_trailer; | 44 union { |
| 45 mach_msg_trailer_t trailer; |
| 46 mach_msg_audit_trailer_t audit_trailer; |
| 47 }; |
44 }; | 48 }; |
45 | 49 |
46 } // namespace | 50 } // namespace |
47 | 51 |
48 namespace crashpad { | 52 namespace crashpad { |
49 namespace test { | 53 namespace test { |
50 | 54 |
51 namespace internal { | 55 namespace internal { |
52 | 56 |
53 struct MachMultiprocessInfo { | 57 struct MachMultiprocessInfo { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } | 117 } |
114 | 118 |
115 task_t MachMultiprocess::ChildTask() const { | 119 task_t MachMultiprocess::ChildTask() const { |
116 EXPECT_NE(TASK_NULL, info_->child_task); | 120 EXPECT_NE(TASK_NULL, info_->child_task); |
117 return info_->child_task; | 121 return info_->child_task; |
118 } | 122 } |
119 | 123 |
120 void MachMultiprocess::MultiprocessParent() { | 124 void MachMultiprocess::MultiprocessParent() { |
121 ReceiveHelloMessage message = {}; | 125 ReceiveHelloMessage message = {}; |
122 | 126 |
123 kern_return_t kr = | 127 kern_return_t kr = mach_msg(&message.header, |
124 mach_msg(&message.header, | 128 MACH_RCV_MSG | kMachMessageReceiveAuditTrailer, |
125 MACH_RCV_MSG | MACH_RCV_TRAILER_TYPE(MACH_MSG_TRAILER_FORMAT_0) | | 129 0, |
126 MACH_RCV_TRAILER_ELEMENTS(MACH_RCV_TRAILER_AUDIT), | 130 sizeof(message), |
127 0, | 131 info_->local_port, |
128 sizeof(message), | 132 MACH_MSG_TIMEOUT_NONE, |
129 info_->local_port, | 133 MACH_PORT_NULL); |
130 MACH_MSG_TIMEOUT_NONE, | |
131 MACH_PORT_NULL); | |
132 ASSERT_EQ(MACH_MSG_SUCCESS, kr) << MachErrorMessage(kr, "mach_msg"); | 134 ASSERT_EQ(MACH_MSG_SUCCESS, kr) << MachErrorMessage(kr, "mach_msg"); |
133 | 135 |
134 // Comb through the entire message, checking every field against its expected | 136 // Comb through the entire message, checking every field against its expected |
135 // value. | 137 // value. |
136 EXPECT_EQ(MACH_MSGH_BITS(MACH_MSG_TYPE_MOVE_SEND, MACH_MSG_TYPE_MOVE_SEND) | | 138 EXPECT_EQ(MACH_MSGH_BITS(MACH_MSG_TYPE_MOVE_SEND, MACH_MSG_TYPE_MOVE_SEND) | |
137 MACH_MSGH_BITS_COMPLEX, | 139 MACH_MSGH_BITS_COMPLEX, |
138 message.header.msgh_bits); | 140 message.header.msgh_bits); |
139 ASSERT_EQ(sizeof(SendHelloMessage), message.header.msgh_size); | 141 ASSERT_EQ(sizeof(SendHelloMessage), message.header.msgh_size); |
140 EXPECT_EQ(info_->local_port, message.header.msgh_local_port); | 142 EXPECT_EQ(info_->local_port, message.header.msgh_local_port); |
141 ASSERT_EQ(1u, message.body.msgh_descriptor_count); | 143 ASSERT_EQ(1u, message.body.msgh_descriptor_count); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 gid_t audit_rgid = audit_token_to_rgid(message.audit_trailer.msgh_audit); | 181 gid_t audit_rgid = audit_token_to_rgid(message.audit_trailer.msgh_audit); |
180 pid_t audit_pid = audit_token_to_pid(message.audit_trailer.msgh_audit); | 182 pid_t audit_pid = audit_token_to_pid(message.audit_trailer.msgh_audit); |
181 au_asid_t audit_asid = audit_token_to_asid(message.audit_trailer.msgh_audit); | 183 au_asid_t audit_asid = audit_token_to_asid(message.audit_trailer.msgh_audit); |
182 #endif | 184 #endif |
183 EXPECT_EQ(geteuid(), audit_euid); | 185 EXPECT_EQ(geteuid(), audit_euid); |
184 EXPECT_EQ(getegid(), audit_egid); | 186 EXPECT_EQ(getegid(), audit_egid); |
185 EXPECT_EQ(getuid(), audit_ruid); | 187 EXPECT_EQ(getuid(), audit_ruid); |
186 EXPECT_EQ(getgid(), audit_rgid); | 188 EXPECT_EQ(getgid(), audit_rgid); |
187 ASSERT_EQ(ChildPID(), audit_pid); | 189 ASSERT_EQ(ChildPID(), audit_pid); |
188 | 190 |
| 191 ASSERT_EQ(ChildPID(), AuditPIDFromMachMessageTrailer(&message.trailer)); |
| 192 |
189 auditinfo_addr_t audit_info; | 193 auditinfo_addr_t audit_info; |
190 int rv = getaudit_addr(&audit_info, sizeof(audit_info)); | 194 int rv = getaudit_addr(&audit_info, sizeof(audit_info)); |
191 ASSERT_EQ(0, rv) << ErrnoMessage("getaudit_addr"); | 195 ASSERT_EQ(0, rv) << ErrnoMessage("getaudit_addr"); |
192 EXPECT_EQ(audit_info.ai_auid, audit_auid); | 196 EXPECT_EQ(audit_info.ai_auid, audit_auid); |
193 EXPECT_EQ(audit_info.ai_asid, audit_asid); | 197 EXPECT_EQ(audit_info.ai_asid, audit_asid); |
194 | 198 |
195 // Retrieve the remote port from the message header, and the child’s task port | 199 // Retrieve the remote port from the message header, and the child’s task port |
196 // from the message body. | 200 // from the message body. |
197 info_->remote_port.reset(message.header.msgh_remote_port); | 201 info_->remote_port.reset(message.header.msgh_remote_port); |
198 info_->child_task.reset(message.port_descriptor.name); | 202 info_->child_task.reset(message.port_descriptor.name); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 if (testing::Test::HasFailure()) { | 271 if (testing::Test::HasFailure()) { |
268 // Trigger the ScopedForbidReturn destructor. | 272 // Trigger the ScopedForbidReturn destructor. |
269 return; | 273 return; |
270 } | 274 } |
271 | 275 |
272 forbid_return.Disarm(); | 276 forbid_return.Disarm(); |
273 } | 277 } |
274 | 278 |
275 } // namespace test | 279 } // namespace test |
276 } // namespace crashpad | 280 } // namespace crashpad |
OLD | NEW |