Пример #1
0
/* Returns true if the given address is within the code segment. Generates
 * error messages if it isn't.
 */
static INLINE Bool NaClCheckAddressRange(NaClPcAddress address,
                                         NaClValidatorState* state) {
  if (address >= state->codesize) {
    NaClValidatorPcAddressMessage(LOG_ERROR, state, address,
                                  "Jump to address outside code segment.\n");
    return FALSE;
  }
  return TRUE;
}
Пример #2
0
void NaClJumpValidatorSummarize(NaClValidatorState* vstate) {
  /* Check that any explicit jump is to a possible (atomic) sequence
   * of disassembled instructions.
   */
  NaClJumpSets* jump_sets;
  NaClPcAddress addr;
  size_t i;
  if (vstate->quit) return;
  jump_sets = &vstate->jump_sets;
  NaClValidatorMessage(
      LOG_INFO, vstate,
      "Checking jump targets: %"NACL_PRIxNaClPcAddress
      " to %"NACL_PRIxNaClPcAddress"\n",
      vstate->vbase, vstate->vbase + vstate->codesize);

  /* (Low level) Walk the collected sets to find address that correspond
   * to branches into an atomic sequence of instructions.
   */
  for (i = 0; i < jump_sets->set_array_size; ++i) {
    uint8_t problem = jump_sets->actual_targets[i] &
        (~jump_sets->possible_targets[i] |
         jump_sets->removed_targets[i]);
    if (problem) {
      /* Some bit in this range is a problem, so we will convert back
       * to code like the above and test each bit separately.
       */
      NaClPcAddress j;
      NaClPcAddress base = (i << 3);
      for (j = 0; j < 8; ++j) {
        addr = base + j;
        if (addr < vstate->codesize) {
          if (NaClAddressSetContains(jump_sets->actual_targets, addr, vstate)) {
            DEBUG(NaClLog(LOG_INFO,
                          "Checking jump address: %"NACL_PRIxNaClPcAddress"\n",
                          addr));
            if (!IsNaClReachableAddress(vstate, addr)) {
              NaClValidatorPcAddressMessage(LOG_ERROR, vstate, addr,
                                            "Bad jump target\n");
            }
          }
        }
      }
    }
  }

  /* Check that all block boundaries are accessable at an aligned address. */
  NaClValidatorMessage(
      LOG_INFO, vstate, "Checking that basic blocks are aligned\n");
  if (vstate->vbase & vstate->bundle_mask) {
    NaClValidatorMessage(LOG_ERROR, vstate,
                         "Code segment starts at 0x%"NACL_PRIxNaClPcAddress", "
                         "which isn't aligned properly.\n",
                         vstate->vbase);
  } else {
    for (addr = 0; addr < vstate->codesize; addr += vstate->bundle_size) {
      DEBUG(NaClLog(LOG_INFO,
                    "Checking block address: %"NACL_PRIxNaClPcAddress"\n",
                    addr));
      if (!IsNaClReachableAddress(vstate, addr)) {
        NaClValidatorPcAddressMessage(LOG_ERROR, vstate, addr,
                                      "Bad basic block alignment.\n");
      }
    }
  }
}