| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 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 /* | 7 /* |
| 8 * nc_jumps.c - Validate where valid jumps can occur. | 8 * nc_jumps.c - Validate where valid jumps can occur. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 NaClAddressSetAddInline(jump_sets->actual_targets, to_address, state); | 90 NaClAddressSetAddInline(jump_sets->actual_targets, to_address, state); |
| 91 } | 91 } |
| 92 /* The range check may not be strictly necessary given that we have | 92 /* The range check may not be strictly necessary given that we have |
| 93 * guard regions around the sandbox address space, but it shouldn't | 93 * guard regions around the sandbox address space, but it shouldn't |
| 94 * hurt to disallow branches that overflow or underflow the address | 94 * hurt to disallow branches that overflow or underflow the address |
| 95 * space. | 95 * space. |
| 96 */ | 96 */ |
| 97 else if ((to_address & state->alignment_mask) == 0 && | 97 else if ((to_address & state->alignment_mask) == 0 && |
| 98 (to_address & ~(NaClPcAddress) 0xffffffff) == 0) { | 98 (to_address & ~(NaClPcAddress) 0xffffffff) == 0) { |
| 99 /* Allow bundle-aligned jump. */ | 99 /* Allow bundle-aligned jump. */ |
| 100 } | 100 } else if (inst->unchanged) { |
| 101 else { | 101 /* If we are replacing this instruction during dynamic code modification |
| 102 * and it has not changed, the jump target must be valid because the |
| 103 * instruction has been previously validated. However, we may be only |
| 104 * replacing a subsection of the code segment and therefore may not have |
| 105 * information about instruction boundaries outside of the code being |
| 106 * replaced. Therefore, we allow unaligned direct jumps outside of the code |
| 107 * being validated if and only if the instruction is unchanged. |
| 108 * If dynamic code replacement is not being performed, inst->unchanged |
| 109 * should always be false. |
| 110 */ |
| 111 } else { |
| 102 NaClValidatorInstMessage(LOG_ERROR, state, inst, | 112 NaClValidatorInstMessage(LOG_ERROR, state, inst, |
| 103 "Instruction jumps to bad address\n"); | 113 "Instruction jumps to bad address\n"); |
| 104 } | 114 } |
| 105 } | 115 } |
| 106 | 116 |
| 107 static Bool NaClExtractBinaryOperandIndices( | 117 static Bool NaClExtractBinaryOperandIndices( |
| 108 NaClInstState* inst, | 118 NaClInstState* inst, |
| 109 int* op_1, | 119 int* op_1, |
| 110 int* op_2) { | 120 int* op_2) { |
| 111 uint32_t index; | 121 uint32_t index; |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 * the call to NaClRememberIp in JumpValidator. | 639 * the call to NaClRememberIp in JumpValidator. |
| 630 */ | 640 */ |
| 631 } else { | 641 } else { |
| 632 DEBUG(NaClLog(LOG_INFO, | 642 DEBUG(NaClLog(LOG_INFO, |
| 633 "Mark instruction as jump illegal: %"NACL_PRIxNaClPcAddress | 643 "Mark instruction as jump illegal: %"NACL_PRIxNaClPcAddress |
| 634 "\n", | 644 "\n", |
| 635 pc)); | 645 pc)); |
| 636 NaClAddressSetAddInline(state->jump_sets.removed_targets, pc, state); | 646 NaClAddressSetAddInline(state->jump_sets.removed_targets, pc, state); |
| 637 } | 647 } |
| 638 } | 648 } |
| OLD | NEW |