OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "native_client/src/trusted/manifest_name_service_proxy/manifest_proxy.h
" | 9 #include "native_client/src/trusted/manifest_name_service_proxy/manifest_proxy.h
" |
10 | 10 |
11 #include "native_client/src/shared/platform/nacl_log.h" | 11 #include "native_client/src/shared/platform/nacl_log.h" |
12 #include "native_client/src/shared/platform/nacl_sync.h" | 12 #include "native_client/src/shared/platform/nacl_sync.h" |
13 #include "native_client/src/shared/platform/nacl_sync_checked.h" | 13 #include "native_client/src/shared/platform/nacl_sync_checked.h" |
14 #include "native_client/src/shared/srpc/nacl_srpc.h" | 14 #include "native_client/src/shared/srpc/nacl_srpc.h" |
| 15 #include "native_client/src/trusted/desc/nacl_desc_io.h" |
15 #include "native_client/src/trusted/reverse_service/manifest_rpc.h" | 16 #include "native_client/src/trusted/reverse_service/manifest_rpc.h" |
16 #include "native_client/src/trusted/reverse_service/reverse_control_rpc.h" | 17 #include "native_client/src/trusted/reverse_service/reverse_control_rpc.h" |
17 #include "native_client/src/trusted/service_runtime/include/sys/errno.h" | 18 #include "native_client/src/trusted/service_runtime/include/sys/errno.h" |
| 19 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" |
18 #include "native_client/src/trusted/service_runtime/include/sys/nacl_name_servic
e.h" | 20 #include "native_client/src/trusted/service_runtime/include/sys/nacl_name_servic
e.h" |
19 #include "native_client/src/trusted/service_runtime/nacl_secure_service.h" | 21 #include "native_client/src/trusted/service_runtime/nacl_secure_service.h" |
| 22 #include "native_client/src/trusted/validator/rich_file_info.h" |
| 23 #include "native_client/src/trusted/validator/validation_cache.h" |
20 | 24 |
21 static void NaClManifestWaitForChannel_yield_mu( | 25 static void NaClManifestWaitForChannel_yield_mu( |
22 struct NaClManifestProxyConnection *self) { | 26 struct NaClManifestProxyConnection *self) { |
23 NaClLog(4, "Entered NaClManifestWaitForChannel_yield_mu\n"); | 27 NaClLog(4, "Entered NaClManifestWaitForChannel_yield_mu\n"); |
24 NaClXMutexLock(&self->mu); | 28 NaClXMutexLock(&self->mu); |
25 NaClLog(4, "NaClManifestWaitForChannel_yield_mu: checking channel\n"); | 29 NaClLog(4, "NaClManifestWaitForChannel_yield_mu: checking channel\n"); |
26 while (!self->channel_initialized) { | 30 while (!self->channel_initialized) { |
27 NaClLog(4, "NaClManifestWaitForChannel_yield_mu: waiting\n"); | 31 NaClLog(4, "NaClManifestWaitForChannel_yield_mu: waiting\n"); |
28 NaClXCondVarWait(&self->cv, &self->mu); | 32 NaClXCondVarWait(&self->cv, &self->mu); |
29 } | 33 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 struct NaClSrpcArg **out_args, | 105 struct NaClSrpcArg **out_args, |
102 struct NaClSrpcClosure *done_cls) { | 106 struct NaClSrpcClosure *done_cls) { |
103 struct NaClManifestProxyConnection *proxy_conn = | 107 struct NaClManifestProxyConnection *proxy_conn = |
104 (struct NaClManifestProxyConnection *) rpc->channel->server_instance_data; | 108 (struct NaClManifestProxyConnection *) rpc->channel->server_instance_data; |
105 char *name = in_args[0]->arrays.str; | 109 char *name = in_args[0]->arrays.str; |
106 int flags = in_args[1]->u.ival; | 110 int flags = in_args[1]->u.ival; |
107 char cookie[20]; | 111 char cookie[20]; |
108 uint32_t cookie_size = sizeof cookie; | 112 uint32_t cookie_size = sizeof cookie; |
109 int status; | 113 int status; |
110 struct NaClDesc *desc; | 114 struct NaClDesc *desc; |
| 115 uint64_t nonce; |
111 NaClSrpcError srpc_error; | 116 NaClSrpcError srpc_error; |
112 | 117 |
113 NaClLog(4, "NaClManifestNameServiceLookupRpc\n"); | 118 NaClLog(4, "NaClManifestNameServiceLookupRpc\n"); |
114 | 119 |
115 NaClManifestWaitForChannel_yield_mu(proxy_conn); | 120 NaClManifestWaitForChannel_yield_mu(proxy_conn); |
116 | 121 |
117 NaClLog(4, | 122 NaClLog(4, |
118 "NaClManifestNameServiceLookupRpc: name %s, flags %d\n", | 123 "NaClManifestNameServiceLookupRpc: name %s, flags %d\n", |
119 name, flags); | 124 name, flags); |
120 NaClLog(4, | 125 NaClLog(4, |
121 "NaClManifestNameServiceLookupRpc: invoking %s\n", | 126 "NaClManifestNameServiceLookupRpc: invoking %s\n", |
122 NACL_MANIFEST_LOOKUP); | 127 NACL_MANIFEST_LOOKUP); |
123 | 128 |
124 if (NACL_SRPC_RESULT_OK != | 129 if (NACL_SRPC_RESULT_OK != |
125 (srpc_error = | 130 (srpc_error = |
126 NaClSrpcInvokeBySignature(&proxy_conn->client_channel, | 131 NaClSrpcInvokeBySignature(&proxy_conn->client_channel, |
127 NACL_MANIFEST_LOOKUP, | 132 NACL_MANIFEST_LOOKUP, |
128 name, | 133 name, |
129 flags, | 134 flags, |
130 &status, | 135 &status, |
131 &desc, | 136 &desc, |
| 137 &nonce, |
132 &cookie_size, | 138 &cookie_size, |
133 cookie))) { | 139 cookie))) { |
134 NaClLog(LOG_ERROR, | 140 NaClLog(LOG_ERROR, |
135 ("Manifest lookup via channel 0x%"NACL_PRIxPTR" with RPC " | 141 ("Manifest lookup via channel 0x%"NACL_PRIxPTR" with RPC " |
136 NACL_MANIFEST_LOOKUP" failed: %d\n"), | 142 NACL_MANIFEST_LOOKUP" failed: %d\n"), |
137 (uintptr_t) &proxy_conn->client_channel, | 143 (uintptr_t) &proxy_conn->client_channel, |
138 srpc_error); | 144 srpc_error); |
139 rpc->result = srpc_error; | 145 rpc->result = srpc_error; |
140 } else { | 146 } else { |
| 147 struct NaClManifestProxy *proxy = |
| 148 (struct NaClManifestProxy *) proxy_conn->base.server; |
| 149 struct NaClValidationCache *validation_cache = proxy->nap->validation_cache; |
| 150 int32_t new_fd; |
| 151 char *file_path; |
| 152 uint32_t file_path_length; |
| 153 |
141 NaClLog(4, | 154 NaClLog(4, |
142 "NaClManifestNameServiceLookupRpc: got cookie %.*s\n", | 155 "NaClManifestNameServiceLookupRpc: got cookie %.*s\n", |
143 cookie_size, cookie); | 156 cookie_size, cookie); |
| 157 |
| 158 if (nonce != 0 && validation_cache->ResolveFileNonce != NULL && |
| 159 validation_cache->ResolveFileNonce(validation_cache->handle, nonce, |
| 160 &new_fd, &file_path, |
| 161 &file_path_length)) { |
| 162 struct RichFileInfo info; |
| 163 uint32_t flags; |
| 164 /* |
| 165 * We don't entirely trust the render process, so swap the handle with one |
| 166 * from the browser process that should be equivalent. |
| 167 */ |
| 168 NaClDescUnref(desc); |
| 169 desc = NaClDescIoDescFromHandleAllocCtor((NaClHandle) new_fd, |
| 170 NACL_ABI_O_RDONLY); |
| 171 |
| 172 /* Mark the desc as OK for mmaping. */ |
| 173 flags = NaClDescGetFlags(desc); |
| 174 NaClDescSetFlags(desc, flags | NACL_DESC_FLAGS_MMAP_EXEC_OK); |
| 175 |
| 176 /* Provide metadata for validation. */ |
| 177 RichFileInfoCtor(&info); |
| 178 info.known_file = 1; |
| 179 info.file_path = file_path; /* Takes ownership. */ |
| 180 info.file_path_length = file_path_length; |
| 181 SetFileOriginInfo(desc, &info); |
| 182 RichFileInfoDtor(&info); |
| 183 } |
| 184 |
144 out_args[0]->u.ival = status; | 185 out_args[0]->u.ival = status; |
145 out_args[1]->u.hval = desc; | 186 out_args[1]->u.hval = desc; |
146 rpc->result = NACL_SRPC_RESULT_OK; | 187 rpc->result = NACL_SRPC_RESULT_OK; |
147 } | 188 } |
148 (*done_cls->Run)(done_cls); | 189 (*done_cls->Run)(done_cls); |
149 NaClDescUnref(desc); | 190 NaClDescUnref(desc); |
150 NaClManifestReleaseChannel_release_mu(proxy_conn); | 191 NaClManifestReleaseChannel_release_mu(proxy_conn); |
151 } | 192 } |
152 | 193 |
153 static void NaClManifestNameServiceDeleteRpc( | 194 static void NaClManifestNameServiceDeleteRpc( |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 /* | 432 /* |
392 * The NaClManifestProxyConnectionFactory creates a subclass of a | 433 * The NaClManifestProxyConnectionFactory creates a subclass of a |
393 * NaClSimpleServiceConnectionFactory object that uses the reverse | 434 * NaClSimpleServiceConnectionFactory object that uses the reverse |
394 * connection object nap->reverse_client to obtain a new RPC channel | 435 * connection object nap->reverse_client to obtain a new RPC channel |
395 * with each manifest connection. | 436 * with each manifest connection. |
396 */ | 437 */ |
397 NaClSimpleServiceAcceptConnection, | 438 NaClSimpleServiceAcceptConnection, |
398 NaClSimpleServiceAcceptAndSpawnHandler, | 439 NaClSimpleServiceAcceptAndSpawnHandler, |
399 NaClSimpleServiceRpcHandler, | 440 NaClSimpleServiceRpcHandler, |
400 }; | 441 }; |
OLD | NEW |