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 #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 |
11 /* Translate validation status to values wanted by sel_ldr. */ | 11 /* Translate validation status to values wanted by sel_ldr. */ |
12 static int NaClValidateStatus(NaClValidationStatus status) { | 12 static int NaClValidateStatus(NaClValidationStatus status) { |
13 switch (status) { | 13 switch (status) { |
14 case NaClValidationSucceeded: | 14 case NaClValidationSucceeded: |
15 return LOAD_OK; | 15 return LOAD_OK; |
16 case NaClValidationFailedOutOfMemory: | 16 case NaClValidationFailedOutOfMemory: |
17 /* Note: this is confusing, but is what sel_ldr is expecting. */ | 17 /* Note: this is confusing, but is what sel_ldr is expecting. */ |
18 return LOAD_BAD_FILE; | 18 return LOAD_BAD_FILE; |
19 case NaClValidationFailed: | 19 case NaClValidationFailed: |
20 case NaClValidationFailedNotImplemented: | 20 case NaClValidationFailedNotImplemented: |
21 case NaClValidationFailedCpuNotSupported: | 21 case NaClValidationFailedCpuNotSupported: |
22 case NaClValidationFailedSegmentationIssue: | 22 case NaClValidationFailedSegmentationIssue: |
23 default: | 23 default: |
24 return LOAD_VALIDATION_FAILED; | 24 return LOAD_VALIDATION_FAILED; |
25 } | 25 } |
26 } | 26 } |
27 | 27 |
| 28 enum NaClSBKind getSBKind(struct NaClApp *nap) { |
| 29 enum NaClSBKind sb_kind = NACL_SB_DEFAULT; |
| 30 #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_arm |
| 31 uintptr_t entry = nap->user_entry_pt ? |
| 32 nap->user_entry_pt : nap->initial_entry_pt; |
| 33 sb_kind = (entry & 1) ? NACL_SB_ARM_THUMB2 : sb_kind; |
| 34 #else |
| 35 UNREFERENCED_PARAMETER(nap); |
| 36 #endif |
| 37 return sb_kind; |
| 38 } |
| 39 |
28 int NaClValidateCode(struct NaClApp *nap, uintptr_t guest_addr, | 40 int NaClValidateCode(struct NaClApp *nap, uintptr_t guest_addr, |
29 uint8_t *data, size_t size) { | 41 uint8_t *data, size_t size) { |
30 NaClValidationStatus status = NaClValidationSucceeded; | 42 NaClValidationStatus status = NaClValidationSucceeded; |
31 enum NaClSBKind sb_kind = NACL_SB_DEFAULT; | 43 enum NaClSBKind sb_kind = getSBKind(nap); |
32 if (nap->validator_stub_out_mode) { | 44 if (nap->validator_stub_out_mode) { |
33 /* In stub out mode, we do two passes. The second pass acts as a | 45 /* In stub out mode, we do two passes. The second pass acts as a |
34 sanity check that bad instructions were indeed overwritten with | 46 sanity check that bad instructions were indeed overwritten with |
35 allowable HLTs. */ | 47 allowable HLTs. */ |
36 status = NACL_SUBARCH_NAME(ApplyValidator, | 48 status = NACL_SUBARCH_NAME(ApplyValidator, |
37 NACL_TARGET_ARCH, | 49 NACL_TARGET_ARCH, |
38 NACL_TARGET_SUBARCH)( | 50 NACL_TARGET_SUBARCH)( |
39 sb_kind, | 51 sb_kind, |
40 NaClApplyValidationDoStubout, | 52 NaClApplyValidationDoStubout, |
41 guest_addr, data, size, | 53 guest_addr, data, size, |
42 nap->bundle_size, TRUE); | 54 nap->bundle_size, TRUE); |
43 } | 55 } |
44 if (status == NaClValidationSucceeded) { | 56 if (status == NaClValidationSucceeded) { |
45 status = NACL_SUBARCH_NAME(ApplyValidator, | 57 status = NACL_SUBARCH_NAME(ApplyValidator, |
46 NACL_TARGET_ARCH, | 58 NACL_TARGET_ARCH, |
47 NACL_TARGET_SUBARCH)( | 59 NACL_TARGET_SUBARCH)( |
48 sb_kind, | 60 sb_kind, |
49 NaClApplyCodeValidation, | 61 NaClApplyCodeValidation, |
50 guest_addr, data, size, | 62 guest_addr, data, size, |
51 nap->bundle_size, TRUE); | 63 nap->bundle_size, TRUE); |
52 } | 64 } |
53 return NaClValidateStatus(status); | 65 return NaClValidateStatus(status); |
54 } | 66 } |
55 | 67 |
56 int NaClValidateCodeReplacement(struct NaClApp *nap, uintptr_t guest_addr, | 68 int NaClValidateCodeReplacement(struct NaClApp *nap, uintptr_t guest_addr, |
57 uint8_t *data_old, uint8_t *data_new, | 69 uint8_t *data_old, uint8_t *data_new, |
58 size_t size) { | 70 size_t size) { |
59 enum NaClSBKind sb_kind = NACL_SB_DEFAULT; | 71 enum NaClSBKind sb_kind = getSBKind(nap); |
60 if (nap->validator_stub_out_mode) return LOAD_BAD_FILE; | 72 if (nap->validator_stub_out_mode) return LOAD_BAD_FILE; |
61 | 73 |
62 if ((guest_addr % nap->bundle_size) != 0 || | 74 if ((guest_addr % nap->bundle_size) != 0 || |
63 (size % nap->bundle_size) != 0) { | 75 (size % nap->bundle_size) != 0) { |
64 return LOAD_BAD_FILE; | 76 return LOAD_BAD_FILE; |
65 } | 77 } |
66 | |
67 return NaClValidateStatus( | 78 return NaClValidateStatus( |
68 NACL_SUBARCH_NAME(ApplyValidatorCodeReplacement, | 79 NACL_SUBARCH_NAME(ApplyValidatorCodeReplacement, |
69 NACL_TARGET_ARCH, | 80 NACL_TARGET_ARCH, |
70 NACL_TARGET_SUBARCH) | 81 NACL_TARGET_SUBARCH) |
71 (sb_kind, guest_addr, data_old, data_new, size, nap->bundle_size)); | 82 (sb_kind, guest_addr, data_old, data_new, size, nap->bundle_size)); |
72 } | 83 } |
73 | 84 |
74 int NaClCopyCode(struct NaClApp *nap, uintptr_t guest_addr, | 85 int NaClCopyCode(struct NaClApp *nap, uintptr_t guest_addr, |
75 uint8_t *data_old, uint8_t *data_new, | 86 uint8_t *data_old, uint8_t *data_new, |
76 size_t size) { | 87 size_t size) { |
77 enum NaClSBKind sb_kind = NACL_SB_DEFAULT; | 88 enum NaClSBKind sb_kind = getSBKind(nap); |
78 return NaClValidateStatus( | 89 return NaClValidateStatus( |
79 NACL_SUBARCH_NAME(ApplyValidatorCopy, | 90 NACL_SUBARCH_NAME(ApplyValidatorCopy, |
80 NACL_TARGET_ARCH, | 91 NACL_TARGET_ARCH, |
81 NACL_TARGET_SUBARCH) | 92 NACL_TARGET_SUBARCH) |
82 (sb_kind, guest_addr, data_old, data_new, size, nap->bundle_size)); | 93 (sb_kind, guest_addr, data_old, data_new, size, nap->bundle_size)); |
83 } | 94 } |
84 | 95 |
85 NaClErrorCode NaClValidateImage(struct NaClApp *nap) { | 96 NaClErrorCode NaClValidateImage(struct NaClApp *nap) { |
86 uintptr_t memp; | 97 uintptr_t memp; |
87 uintptr_t endp; | 98 uintptr_t endp; |
(...skipping 22 matching lines...) Expand all Loading... |
110 NaClLog(LOG_ERROR, | 121 NaClLog(LOG_ERROR, |
111 "Run sel_ldr in debug mode to ignore validation failure.\n"); | 122 "Run sel_ldr in debug mode to ignore validation failure.\n"); |
112 NaClLog(LOG_ERROR, | 123 NaClLog(LOG_ERROR, |
113 "Run ncval <module-name> for validation error details.\n"); | 124 "Run ncval <module-name> for validation error details.\n"); |
114 rcode = LOAD_VALIDATION_FAILED; | 125 rcode = LOAD_VALIDATION_FAILED; |
115 } | 126 } |
116 } | 127 } |
117 } | 128 } |
118 return rcode; | 129 return rcode; |
119 } | 130 } |
OLD | NEW |