| 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 "native_client/src/shared/platform/nacl_log.h" | 7 #include "native_client/src/shared/platform/nacl_log.h" |
| 8 #include "native_client/src/trusted/service_runtime/sel_ldr.h" | 8 #include "native_client/src/trusted/service_runtime/sel_ldr.h" |
| 9 #include "native_client/src/trusted/validator/ncvalidate.h" | 9 #include "native_client/src/trusted/validator/ncvalidate.h" |
| 10 | 10 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 /* Validation caching is currently incompatible with stubout. */ | 65 /* Validation caching is currently incompatible with stubout. */ |
| 66 cache = NULL; | 66 cache = NULL; |
| 67 /* In stub out mode, we do two passes. The second pass acts as a | 67 /* In stub out mode, we do two passes. The second pass acts as a |
| 68 sanity check that bad instructions were indeed overwritten with | 68 sanity check that bad instructions were indeed overwritten with |
| 69 allowable HLTs. */ | 69 allowable HLTs. */ |
| 70 status = NACL_SUBARCH_NAME(ApplyValidator, | 70 status = NACL_SUBARCH_NAME(ApplyValidator, |
| 71 NACL_TARGET_ARCH, | 71 NACL_TARGET_ARCH, |
| 72 NACL_TARGET_SUBARCH)( | 72 NACL_TARGET_SUBARCH)( |
| 73 sb_kind, | 73 sb_kind, |
| 74 guest_addr, data, size, | 74 guest_addr, data, size, |
| 75 nap->bundle_size, | |
| 76 TRUE, /* stub out */ | 75 TRUE, /* stub out */ |
| 77 FALSE, /* text is not read-only */ | 76 FALSE, /* text is not read-only */ |
| 78 &nap->cpu_features, | 77 &nap->cpu_features, |
| 79 cache); | 78 cache); |
| 80 } | 79 } |
| 81 if (status == NaClValidationSucceeded) { | 80 if (status == NaClValidationSucceeded) { |
| 82 /* Fixed feature CPU mode implies read-only */ | 81 /* Fixed feature CPU mode implies read-only */ |
| 83 int readonly_text = nap->fixed_feature_cpu_mode; | 82 int readonly_text = nap->fixed_feature_cpu_mode; |
| 84 status = NACL_SUBARCH_NAME(ApplyValidator, | 83 status = NACL_SUBARCH_NAME(ApplyValidator, |
| 85 NACL_TARGET_ARCH, | 84 NACL_TARGET_ARCH, |
| 86 NACL_TARGET_SUBARCH)( | 85 NACL_TARGET_SUBARCH)( |
| 87 sb_kind, | 86 sb_kind, |
| 88 guest_addr, data, size, | 87 guest_addr, data, size, |
| 89 nap->bundle_size, | |
| 90 FALSE, /* do not stub out */ | 88 FALSE, /* do not stub out */ |
| 91 readonly_text, | 89 readonly_text, |
| 92 &nap->cpu_features, | 90 &nap->cpu_features, |
| 93 cache); | 91 cache); |
| 94 } | 92 } |
| 95 return NaClValidateStatus(status); | 93 return NaClValidateStatus(status); |
| 96 } | 94 } |
| 97 | 95 |
| 98 int NaClValidateCodeReplacement(struct NaClApp *nap, uintptr_t guest_addr, | 96 int NaClValidateCodeReplacement(struct NaClApp *nap, uintptr_t guest_addr, |
| 99 uint8_t *data_old, uint8_t *data_new, | 97 uint8_t *data_old, uint8_t *data_new, |
| 100 size_t size) { | 98 size_t size) { |
| 101 enum NaClSBKind sb_kind = NACL_SB_DEFAULT; | 99 enum NaClSBKind sb_kind = NACL_SB_DEFAULT; |
| 102 if (nap->validator_stub_out_mode) return LOAD_BAD_FILE; | 100 if (nap->validator_stub_out_mode) return LOAD_BAD_FILE; |
| 103 if (nap->fixed_feature_cpu_mode) return LOAD_BAD_FILE; | 101 if (nap->fixed_feature_cpu_mode) return LOAD_BAD_FILE; |
| 104 | 102 |
| 105 if ((guest_addr % nap->bundle_size) != 0 || | 103 if ((guest_addr % nap->bundle_size) != 0 || |
| 106 (size % nap->bundle_size) != 0) { | 104 (size % nap->bundle_size) != 0) { |
| 107 return LOAD_BAD_FILE; | 105 return LOAD_BAD_FILE; |
| 108 } | 106 } |
| 109 | 107 |
| 110 return NaClValidateStatus( | 108 return NaClValidateStatus( |
| 111 NACL_SUBARCH_NAME(ApplyValidatorCodeReplacement, | 109 NACL_SUBARCH_NAME(ApplyValidatorCodeReplacement, |
| 112 NACL_TARGET_ARCH, | 110 NACL_TARGET_ARCH, |
| 113 NACL_TARGET_SUBARCH) | 111 NACL_TARGET_SUBARCH) |
| 114 (sb_kind, guest_addr, data_old, data_new, size, nap->bundle_size, | 112 (sb_kind, guest_addr, data_old, data_new, size, &nap->cpu_features)); |
| 115 &nap->cpu_features)); | |
| 116 } | 113 } |
| 117 | 114 |
| 118 int NaClCopyCode(struct NaClApp *nap, uintptr_t guest_addr, | 115 int NaClCopyCode(struct NaClApp *nap, uintptr_t guest_addr, |
| 119 uint8_t *data_old, uint8_t *data_new, | 116 uint8_t *data_old, uint8_t *data_new, |
| 120 size_t size) { | 117 size_t size) { |
| 121 enum NaClSBKind sb_kind = NACL_SB_DEFAULT; | 118 enum NaClSBKind sb_kind = NACL_SB_DEFAULT; |
| 122 /* Fixed-feature mode disables any code copying for now. Currently | 119 /* Fixed-feature mode disables any code copying for now. Currently |
| 123 * the only use of NaClCodeCopy() seems to be for dynamic code | 120 * the only use of NaClCodeCopy() seems to be for dynamic code |
| 124 * modification, which should fail in NaClValidateCodeReplacement() | 121 * modification, which should fail in NaClValidateCodeReplacement() |
| 125 * before reaching this. | 122 * before reaching this. |
| 126 */ | 123 */ |
| 127 if (nap->fixed_feature_cpu_mode) return LOAD_BAD_FILE; | 124 if (nap->fixed_feature_cpu_mode) return LOAD_BAD_FILE; |
| 128 return NaClValidateStatus( | 125 return NaClValidateStatus( |
| 129 NACL_SUBARCH_NAME(ApplyValidatorCopy, | 126 NACL_SUBARCH_NAME(ApplyValidatorCopy, |
| 130 NACL_TARGET_ARCH, | 127 NACL_TARGET_ARCH, |
| 131 NACL_TARGET_SUBARCH) | 128 NACL_TARGET_SUBARCH) |
| 132 (sb_kind, guest_addr, data_old, data_new, size, nap->bundle_size, | 129 (sb_kind, guest_addr, data_old, data_new, size, &nap->cpu_features)); |
| 133 &nap->cpu_features)); | |
| 134 } | 130 } |
| 135 | 131 |
| 136 NaClErrorCode NaClValidateImage(struct NaClApp *nap) { | 132 NaClErrorCode NaClValidateImage(struct NaClApp *nap) { |
| 137 uintptr_t memp; | 133 uintptr_t memp; |
| 138 uintptr_t endp; | 134 uintptr_t endp; |
| 139 size_t regionsize; | 135 size_t regionsize; |
| 140 NaClErrorCode rcode; | 136 NaClErrorCode rcode; |
| 141 | 137 |
| 142 memp = nap->mem_start + NACL_TRAMPOLINE_END; | 138 memp = nap->mem_start + NACL_TRAMPOLINE_END; |
| 143 endp = nap->mem_start + nap->static_text_end; | 139 endp = nap->mem_start + nap->static_text_end; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 161 NaClLog(LOG_ERROR, | 157 NaClLog(LOG_ERROR, |
| 162 "Run sel_ldr in debug mode to ignore validation failure.\n"); | 158 "Run sel_ldr in debug mode to ignore validation failure.\n"); |
| 163 NaClLog(LOG_ERROR, | 159 NaClLog(LOG_ERROR, |
| 164 "Run ncval <module-name> for validation error details.\n"); | 160 "Run ncval <module-name> for validation error details.\n"); |
| 165 rcode = LOAD_VALIDATION_FAILED; | 161 rcode = LOAD_VALIDATION_FAILED; |
| 166 } | 162 } |
| 167 } | 163 } |
| 168 } | 164 } |
| 169 return rcode; | 165 return rcode; |
| 170 } | 166 } |
| OLD | NEW |