Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sandbox/mac/os_compatibility.h" | 5 #include "sandbox/mac/os_compatibility.h" |
| 6 | 6 |
| 7 #include <servers/bootstrap.h> | 7 #include <servers/bootstrap.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| 11 | 11 |
| 12 #include "base/mac/mac_util.h" | 12 #include "base/mac/mac_util.h" |
| 13 #include "sandbox/mac/xpc.h" | 13 #include "sandbox/mac/xpc.h" |
| 14 | 14 |
| 15 namespace sandbox { | 15 namespace sandbox { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 #pragma pack(push, 4) | 19 #pragma pack(push, 4) |
| 20 // Verified from launchd-329.3.3 (10.6.8). | 20 struct look_up2_reply_10_7 { |
|
Robert Sesek
2016/04/01 20:00:55
Can you keep this comment and the one on line 48 (
Nico
2016/04/01 20:05:04
Done.
| |
| 21 struct look_up2_request_10_6 { | |
| 22 mach_msg_header_t Head; | |
| 23 NDR_record_t NDR; | |
| 24 name_t servicename; | |
| 25 pid_t targetpid; | |
| 26 uint64_t flags; | |
| 27 }; | |
| 28 | |
| 29 struct look_up2_reply_10_6 { | |
| 30 mach_msg_header_t Head; | 21 mach_msg_header_t Head; |
| 31 mach_msg_body_t msgh_body; | 22 mach_msg_body_t msgh_body; |
| 32 mach_msg_port_descriptor_t service_port; | 23 mach_msg_port_descriptor_t service_port; |
| 33 }; | 24 }; |
| 34 | 25 |
| 35 // Verified from: | 26 // Verified from: |
| 36 // launchd-392.39 (10.7.5) | 27 // launchd-392.39 (10.7.5) |
| 37 // launchd-442.26.2 (10.8.5) | 28 // launchd-442.26.2 (10.8.5) |
| 38 // launchd-842.1.4 (10.9.0) | 29 // launchd-842.1.4 (10.9.0) |
| 39 struct look_up2_request_10_7 { | 30 struct look_up2_request_10_7 { |
| 40 mach_msg_header_t Head; | 31 mach_msg_header_t Head; |
| 41 NDR_record_t NDR; | 32 NDR_record_t NDR; |
| 42 name_t servicename; | 33 name_t servicename; |
| 43 pid_t targetpid; | 34 pid_t targetpid; |
| 44 uuid_t instanceid; | 35 uuid_t instanceid; |
| 45 uint64_t flags; | 36 uint64_t flags; |
| 46 }; | 37 }; |
| 47 | 38 |
| 48 // look_up2_reply_10_7 is the same as the 10_6 version. | |
| 49 | |
| 50 // Verified from: | 39 // Verified from: |
| 51 // launchd-329.3.3 (10.6.8) | 40 // launchd-329.3.3 (10.6.8) |
| 52 // launchd-392.39 (10.7.5) | 41 // launchd-392.39 (10.7.5) |
| 53 // launchd-442.26.2 (10.8.5) | 42 // launchd-442.26.2 (10.8.5) |
| 54 // launchd-842.1.4 (10.9.0) | 43 // launchd-842.1.4 (10.9.0) |
| 55 typedef int vproc_gsk_t; // Defined as an enum in liblaunch/vproc_priv.h. | 44 typedef int vproc_gsk_t; // Defined as an enum in liblaunch/vproc_priv.h. |
| 56 struct swap_integer_request_10_6 { | 45 struct swap_integer_request_10_7 { |
| 57 mach_msg_header_t Head; | 46 mach_msg_header_t Head; |
| 58 NDR_record_t NDR; | 47 NDR_record_t NDR; |
| 59 vproc_gsk_t inkey; | 48 vproc_gsk_t inkey; |
| 60 vproc_gsk_t outkey; | 49 vproc_gsk_t outkey; |
| 61 int64_t inval; | 50 int64_t inval; |
| 62 }; | 51 }; |
| 63 #pragma pack(pop) | 52 #pragma pack(pop) |
| 64 | 53 |
| 65 // TODO(rsesek): Libc provides strnlen() starting in 10.7. | 54 // TODO(rsesek): Libc provides strnlen() starting in 10.7. |
| 66 size_t strnlen(const char* str, size_t maxlen) { | 55 size_t strnlen(const char* str, size_t maxlen) { |
| 67 size_t len = 0; | 56 size_t len = 0; |
| 68 for (; len < maxlen; ++len, ++str) { | 57 for (; len < maxlen; ++len, ++str) { |
| 69 if (*str == '\0') | 58 if (*str == '\0') |
| 70 break; | 59 break; |
| 71 } | 60 } |
| 72 return len; | 61 return len; |
| 73 } | 62 } |
| 74 | 63 |
| 75 class OSCompatibility_10_6 : public OSCompatibility { | 64 class OSCompatibility_10_7 : public OSCompatibility { |
| 76 public: | 65 public: |
| 77 OSCompatibility_10_6() {} | 66 OSCompatibility_10_7() {} |
| 78 ~OSCompatibility_10_6() override {} | 67 ~OSCompatibility_10_7() override {} |
| 79 | 68 |
| 80 uint64_t GetMessageSubsystem(const IPCMessage message) override { | 69 uint64_t GetMessageSubsystem(const IPCMessage message) override { |
| 81 return (message.mach->msgh_id / 100) * 100; | 70 return (message.mach->msgh_id / 100) * 100; |
| 82 } | 71 } |
| 83 | 72 |
| 84 uint64_t GetMessageID(const IPCMessage message) override { | 73 uint64_t GetMessageID(const IPCMessage message) override { |
| 85 return message.mach->msgh_id; | 74 return message.mach->msgh_id; |
| 86 } | 75 } |
| 87 | 76 |
| 88 bool IsServiceLookUpRequest(const IPCMessage message) override { | 77 bool IsServiceLookUpRequest(const IPCMessage message) override { |
| 89 return GetMessageID(message) == 404; | 78 return GetMessageID(message) == 404; |
| 90 } | 79 } |
| 91 | 80 |
| 92 bool IsVprocSwapInteger(const IPCMessage message) override { | 81 bool IsVprocSwapInteger(const IPCMessage message) override { |
| 93 return GetMessageID(message) == 416; | 82 return GetMessageID(message) == 416; |
| 94 } | 83 } |
| 95 | 84 |
| 96 bool IsXPCDomainManagement(const IPCMessage message) override { | 85 bool IsXPCDomainManagement(const IPCMessage message) override { |
| 97 return false; | 86 return false; |
| 98 } | 87 } |
| 99 | 88 |
| 100 std::string GetServiceLookupName(const IPCMessage message) override { | 89 std::string GetServiceLookupName(const IPCMessage message) override { |
| 101 return GetRequestName<look_up2_request_10_6>(message); | 90 return GetRequestName<look_up2_request_10_7>(message); |
| 102 } | 91 } |
| 103 | 92 |
| 104 void WriteServiceLookUpReply(IPCMessage message, | 93 void WriteServiceLookUpReply(IPCMessage message, |
| 105 mach_port_t service_port) override { | 94 mach_port_t service_port) override { |
| 106 auto reply = reinterpret_cast<look_up2_reply_10_6*>(message.mach); | 95 auto reply = reinterpret_cast<look_up2_reply_10_7*>(message.mach); |
| 107 reply->Head.msgh_size = sizeof(*reply); | 96 reply->Head.msgh_size = sizeof(*reply); |
| 108 reply->Head.msgh_bits = | 97 reply->Head.msgh_bits = |
| 109 MACH_MSGH_BITS_REMOTE(MACH_MSG_TYPE_MOVE_SEND_ONCE) | | 98 MACH_MSGH_BITS_REMOTE(MACH_MSG_TYPE_MOVE_SEND_ONCE) | |
| 110 MACH_MSGH_BITS_COMPLEX; | 99 MACH_MSGH_BITS_COMPLEX; |
| 111 reply->msgh_body.msgh_descriptor_count = 1; | 100 reply->msgh_body.msgh_descriptor_count = 1; |
| 112 reply->service_port.name = service_port; | 101 reply->service_port.name = service_port; |
| 113 reply->service_port.disposition = MACH_MSG_TYPE_COPY_SEND; | 102 reply->service_port.disposition = MACH_MSG_TYPE_COPY_SEND; |
| 114 reply->service_port.type = MACH_MSG_PORT_DESCRIPTOR; | 103 reply->service_port.type = MACH_MSG_PORT_DESCRIPTOR; |
| 115 } | 104 } |
| 116 | 105 |
| 117 bool IsSwapIntegerReadOnly(const IPCMessage message) override { | 106 bool IsSwapIntegerReadOnly(const IPCMessage message) override { |
| 118 auto request = | 107 auto request = |
| 119 reinterpret_cast<const swap_integer_request_10_6*>(message.mach); | 108 reinterpret_cast<const swap_integer_request_10_7*>(message.mach); |
| 120 return request->inkey == 0 && request->inval == 0 && request->outkey != 0; | 109 return request->inkey == 0 && request->inval == 0 && request->outkey != 0; |
| 121 } | 110 } |
| 122 | 111 |
| 123 protected: | 112 protected: |
| 124 // The 10.6 and 10.7 implementations are the same except for struct offsets, | 113 // The 10.6 and 10.7 implementations are the same except for struct offsets, |
| 125 // so provide this templatized helper. | 114 // so provide this templatized helper. |
| 126 template <typename R> | 115 template <typename R> |
| 127 static std::string GetRequestName(const IPCMessage message) { | 116 static std::string GetRequestName(const IPCMessage message) { |
| 128 mach_msg_header_t* header = message.mach; | 117 mach_msg_header_t* header = message.mach; |
| 129 DCHECK_EQ(sizeof(R), header->msgh_size); | 118 DCHECK_EQ(sizeof(R), header->msgh_size); |
| 130 const R* request = reinterpret_cast<const R*>(header); | 119 const R* request = reinterpret_cast<const R*>(header); |
| 131 // Make sure the name is properly NUL-terminated. | 120 // Make sure the name is properly NUL-terminated. |
| 132 const size_t name_length = | 121 const size_t name_length = |
| 133 strnlen(request->servicename, BOOTSTRAP_MAX_NAME_LEN); | 122 strnlen(request->servicename, BOOTSTRAP_MAX_NAME_LEN); |
| 134 std::string name = std::string(request->servicename, name_length); | 123 std::string name = std::string(request->servicename, name_length); |
| 135 return name; | 124 return name; |
| 136 } | 125 } |
| 137 }; | 126 }; |
| 138 | 127 |
| 139 class OSCompatibility_10_7 : public OSCompatibility_10_6 { | |
| 140 public: | |
| 141 OSCompatibility_10_7() {} | |
| 142 ~OSCompatibility_10_7() override {} | |
| 143 | |
| 144 std::string GetServiceLookupName(const IPCMessage message) override { | |
| 145 return GetRequestName<look_up2_request_10_7>(message); | |
| 146 } | |
| 147 }; | |
| 148 | |
| 149 class OSCompatibility_10_10 : public OSCompatibility { | 128 class OSCompatibility_10_10 : public OSCompatibility { |
| 150 public: | 129 public: |
| 151 OSCompatibility_10_10() {} | 130 OSCompatibility_10_10() {} |
| 152 ~OSCompatibility_10_10() override {} | 131 ~OSCompatibility_10_10() override {} |
| 153 | 132 |
| 154 uint64_t GetMessageSubsystem(const IPCMessage message) override { | 133 uint64_t GetMessageSubsystem(const IPCMessage message) override { |
| 155 return xpc_dictionary_get_uint64(message.xpc, "subsystem"); | 134 return xpc_dictionary_get_uint64(message.xpc, "subsystem"); |
| 156 } | 135 } |
| 157 | 136 |
| 158 uint64_t GetMessageID(const IPCMessage message) override { | 137 uint64_t GetMessageID(const IPCMessage message) override { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 return xpc_dictionary_get_bool(message.xpc, "set") == false && | 170 return xpc_dictionary_get_bool(message.xpc, "set") == false && |
| 192 xpc_dictionary_get_uint64(message.xpc, "ingsk") == 0 && | 171 xpc_dictionary_get_uint64(message.xpc, "ingsk") == 0 && |
| 193 xpc_dictionary_get_int64(message.xpc, "in") == 0; | 172 xpc_dictionary_get_int64(message.xpc, "in") == 0; |
| 194 } | 173 } |
| 195 }; | 174 }; |
| 196 | 175 |
| 197 } // namespace | 176 } // namespace |
| 198 | 177 |
| 199 // static | 178 // static |
| 200 scoped_ptr<OSCompatibility> OSCompatibility::CreateForPlatform() { | 179 scoped_ptr<OSCompatibility> OSCompatibility::CreateForPlatform() { |
| 201 if (base::mac::IsOSSnowLeopard()) | 180 if (base::mac::IsOSLionOrLater() && base::mac::IsOSMavericksOrEarlier()) |
| 202 return make_scoped_ptr(new OSCompatibility_10_6()); | |
| 203 else if (base::mac::IsOSLionOrLater() && base::mac::IsOSMavericksOrEarlier()) | |
| 204 return make_scoped_ptr(new OSCompatibility_10_7()); | 181 return make_scoped_ptr(new OSCompatibility_10_7()); |
| 205 else | 182 else |
| 206 return make_scoped_ptr(new OSCompatibility_10_10()); | 183 return make_scoped_ptr(new OSCompatibility_10_10()); |
| 207 } | 184 } |
| 208 | 185 |
| 209 OSCompatibility::~OSCompatibility() {} | 186 OSCompatibility::~OSCompatibility() {} |
| 210 | 187 |
| 211 } // namespace sandbox | 188 } // namespace sandbox |
| OLD | NEW |