Ejemplo n.º 1
0
void NaClReplaceDescIfValidationCacheAssertsMappable(
    struct NaClDesc **desc_in_out,
    struct NaClValidationCache *validation_cache) {
  struct NaClDesc *desc = *desc_in_out;
  struct NaClDesc *replacement;
  struct NaClFileToken file_token;

  if (NACL_FI("validation_cache_replacement_bypass", 0, 1)) {
    NaClDescMarkSafeForMmap(desc);
  } else if (!NaClDescGetFileToken(desc, &file_token)) {
    NaClLog(4,
            "NaClReplaceDescIfValidationCacheAssertsMappable: no valid"
            " file token\n");
  } else {
    replacement = NaClExchangeFileTokenForMappableDesc(&file_token,
                                                       validation_cache);
    if (NULL != replacement) {
      NaClDescUnref(desc);
      *desc_in_out = replacement;
    }
  }
}
Ejemplo n.º 2
0
static void NaClManifestNameServiceLookupRpc(
    struct NaClSrpcRpc      *rpc,
    struct NaClSrpcArg      **in_args,
    struct NaClSrpcArg      **out_args,
    struct NaClSrpcClosure  *done_cls) {
  struct NaClManifestProxyConnection  *proxy_conn =
      (struct NaClManifestProxyConnection *) rpc->channel->server_instance_data;
  char                                *name = in_args[0]->arrays.str;
  int                                 flags = in_args[1]->u.ival;
  char                                cookie[20];
  uint32_t                            cookie_size = sizeof cookie;
  int                                 status;
  struct NaClDesc                     *desc;
  struct NaClFileToken                file_token;
  NaClSrpcError                       srpc_error;

  NaClLog(4, "NaClManifestNameServiceLookupRpc\n");

  NaClManifestWaitForChannel_yield_mu(proxy_conn);

  NaClLog(4,
          "NaClManifestNameServiceLookupRpc: name %s, flags %d\n",
          name, flags);
  NaClLog(4,
          "NaClManifestNameServiceLookupRpc: invoking %s\n",
          NACL_MANIFEST_LOOKUP);

  if (NACL_SRPC_RESULT_OK !=
      (srpc_error =
       NaClSrpcInvokeBySignature(&proxy_conn->client_channel,
                                 NACL_MANIFEST_LOOKUP,
                                 name,
                                 flags,
                                 &status,
                                 &desc,
                                 &file_token.lo,
                                 &file_token.hi,
                                 &cookie_size,
                                 cookie))) {
    NaClLog(LOG_ERROR,
            ("Manifest lookup via channel 0x%"NACL_PRIxPTR" with RPC "
             NACL_MANIFEST_LOOKUP" failed: %d\n"),
            (uintptr_t) &proxy_conn->client_channel,
            srpc_error);
    rpc->result = srpc_error;
  } else {
    struct NaClManifestProxy *proxy =
        (struct NaClManifestProxy *) proxy_conn->base.server;
    struct NaClValidationCache *validation_cache =
        proxy->server->nap->validation_cache;
    struct NaClDesc *replacement_desc;

    /*
     * The cookie is used to release renderer-side pepper file handle.
     * For now, we leak.  We need on-close callbacks on NaClDesc
     * objects to do this properly, but even that is insufficient
     * since the manifest NaClDesc could, in principle, be transferred
     * to another process -- we would need distributed garbage
     * protection.  If Pepper could take advantage of host-OS-side
     * reference counting that is already done, this wouldn't be a
     * problem.
     */
    NaClLog(4,
            "NaClManifestNameServiceLookupRpc: got cookie %.*s\n",
            cookie_size, cookie);
    replacement_desc = NaClExchangeFileTokenForMappableDesc(&file_token,
                                                            validation_cache);
    if (NULL != replacement_desc) {
      NaClDescUnref(desc);
      desc = replacement_desc;
    }

    out_args[0]->u.ival = status;
    out_args[1]->u.hval = desc;
    rpc->result = NACL_SRPC_RESULT_OK;
  }
  (*done_cls->Run)(done_cls);
  NaClDescUnref(desc);
  NaClManifestReleaseChannel_release_mu(proxy_conn);
}