Exemplo n.º 1
0
/* updates channel tag */
static void UpdateChannelTag(struct ChannelDesc *channel,
    const char *buffer, int32_t size)
{
  /* skip if etag is not enabled */
  if(!TagEngineEnabled()) return;

  assert(channel != NULL);
  assert(buffer != NULL);

  /* update etag and log information */
  if(size <= 0) return;
  TagUpdate(channel->tag, buffer, size);
}
Exemplo n.º 2
0
int ProxyReport(struct NaClApp *nap)
{
  char report[BIG_ENOUGH_STRING];
  char etag[TAG_DIGEST_SIZE] = TAG_ENGINE_DISABLED;
  int length;
  int i;

  assert(nap != NULL);
  assert(nap->system_manifest != NULL);

  /* tag user memory / channels if session successful */
  if(TagEngineEnabled())
  {
    if(CHANNELS_ETAG_ENABLED) ChannelsDigest(nap);
    if(MEMORY_ETAG_ENABLED) EtagMemoryChunk(nap);
    TagDigest(nap->user_tag, etag);
    TagDtor(nap->user_tag);
  }

  /* for debugging purposes it is useful to see more advanced information */
#ifdef DEBUG
  length = g_snprintf(report, BIG_ENOUGH_STRING,
      "validator state = %d\nuser return code = %d\netag = %s\naccounting = %s\n"
      "exit state = %s\n", nap->validation_state,
      nap->system_manifest->user_ret_code, etag, GetAccountingInfo(), GetExitState());
#else
  /* .. but for production zvm will switch to more brief output */
  length = g_snprintf(report, BIG_ENOUGH_STRING, "%d\n%d\n%s\n%s\n%s\n",
      nap->validation_state, nap->system_manifest->user_ret_code,
      etag, GetAccountingInfo(), GetExitState());
#endif

  /* give the report to proxy */
  i = write(STDOUT_FILENO, report, length);

  /* log the report */
  length = g_snprintf(report, BIG_ENOUGH_STRING,
      "validator state = %d, user return code = %d, etag = %s, accounting = %s, "
      "exit state = %s", nap->validation_state,
      nap->system_manifest->user_ret_code, etag, GetAccountingInfo(), GetExitState());
  ZLOGS(LOG_DEBUG, "%s", report);

  return i == length ? 0 : -1;
}
Exemplo n.º 3
0
/* updates user_tag (should be constructed) with memory chunk data */
static void EtagMemoryChunk(struct NaClApp *nap)
{
  int i;

  assert(nap != NULL);
  assert(TagEngineEnabled() != 0);

  for(i = 0; i < MemMapSize; ++i)
  {
    uintptr_t addr;
    int32_t size;

    /* skip inaccessible pages */
    if(nap->mem_map[RODataIdx].prot == PROT_NONE) continue;

    /* update user_etag with the chunk data */
    addr = nap->mem_map[RODataIdx].page_num << NACL_PAGESHIFT;
    size = nap->mem_map[RODataIdx].npages << NACL_PAGESHIFT;
    TagUpdate(nap->user_tag, (const char*)addr, size);
  }
}
Exemplo n.º 4
0
/* check and update channel EOF state and etag */
static INLINE void UpdateChannelState(struct ChannelDesc *channel)
{
  int64_t more = 0;
  size_t more_size = sizeof more;

  zmq_getsockopt(channel->socket, ZMQ_RCVMORE, &more, &more_size);

  /* etag enabled */
  if(more != 0 && channel->bufend == TAG_DIGEST_SIZE - 1 && CHANNELS_ETAG_ENABLED)
  {
    /* store received digest */
    memcpy(channel->control, zmq_msg_data(&channel->msg), TAG_DIGEST_SIZE - 1);

    /* receive the zero part */
    zmq_recv(channel->socket, &channel->msg, 0);
    channel->bufend = zmq_msg_size(&channel->msg);
    if(channel->bufend == 0) channel->eof = 1;
    else ZLOG(LOG_ERROR, "invalid eof detected on %s", channel->alias);
  }

  /* etag disabled */
  if(more == 0 && channel->bufend == 0 && !TagEngineEnabled())
    channel->eof = 1;
}
Exemplo n.º 5
0
int PrefetchChannelDtor(struct ChannelDesc *channel)
{
  char url[BIG_ENOUGH_STRING];  /* debug purposes only */

  assert(channel != NULL);
  assert(channel->socket != NULL);

  /* log parameters and channel internals */
  MakeURL(url, BIG_ENOUGH_STRING, channel, GetChannelConnectionInfo(channel));
  ZLOGS(LOG_DEBUG, "%s has url %s", channel->alias, url);

  /* close "PUT" channel */
  if(channel->limits[PutsLimit] && channel->limits[PutSizeLimit])
  {
    int size = CHANNELS_ETAG_ENABLED ? TAG_DIGEST_SIZE - 1 : 0;

    /* prepare digest */
    if(TagEngineEnabled())
    {
      TagDigest(channel->tag, channel->digest);
      TagDtor(channel->tag);
    }

    /* send eof */
    channel->eof = 1;
    SendMessage(channel, channel->digest, size);
    ZLOGS(LOG_DEBUG, "%s closed with tag %s, putsize %ld",
        channel->alias, channel->digest, channel->counters[PutSizeLimit]);
  }

  /* close "GET" channel */
  if(channel->limits[GetsLimit] && channel->limits[GetSizeLimit])
  {
    /* wind the channel to the end */
    while(channel->eof == 0)
    {
      char buf[NET_BUFFER_SIZE];
      int32_t size = FetchMessage(channel, buf, NET_BUFFER_SIZE);
      ++channel->counters[GetsLimit];
      channel->counters[GetSizeLimit] += size;

      /* update tag if enabled */
      if(TagEngineEnabled())
        TagUpdate(channel->tag, buf, size);
    }

    /* test integrity (if etag enabled) */
    if(TagEngineEnabled())
    {
      /* prepare digest */
      TagDigest(channel->tag, channel->digest);
      TagDtor(channel->tag);

      /* raise the error if the data corrupted */
      if(memcmp(channel->control, channel->digest, TAG_DIGEST_SIZE) != 0)
      {
        ZLOG(LOG_ERROR, "%s corrupted, control: %s, local: %s",
            channel->alias, channel->control, channel->digest);
        SetExitState("data corrupted");
        SetExitCode(EPIPE);
      }

      ZLOGS(LOG_DEBUG, "%s closed with tag %s, getsize %ld",
          channel->alias, channel->digest, channel->counters[GetSizeLimit]);
    }

    zmq_msg_close(&channel->msg);
    zmq_close(channel->socket);
  }

  /* will destroy context and netlist after all network channels closed */
  NetDtor();

  return 0;
}