Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Side by Side Diff: src/trusted/service_runtime/sel_validate_image.c

Issue 1234393005: A mechanism to identify/forbid/"rewrite" non-temporal instructions (and other) (Closed) Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Patch Set: Fixing nits Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/include/concurrency_ops.h" 7 #include "native_client/src/include/concurrency_ops.h"
8 #include "native_client/src/shared/platform/nacl_log.h" 8 #include "native_client/src/shared/platform/nacl_log.h"
9 #include "native_client/src/shared/utils/types.h" 9 #include "native_client/src/shared/utils/types.h"
10 #include "native_client/src/trusted/service_runtime/sel_ldr.h" 10 #include "native_client/src/trusted/service_runtime/sel_ldr.h"
(...skipping 17 matching lines...) Expand all
28 return LOAD_VALIDATION_FAILED; 28 return LOAD_VALIDATION_FAILED;
29 } 29 }
30 } 30 }
31 31
32 int NaClValidateCode(struct NaClApp *nap, uintptr_t guest_addr, 32 int NaClValidateCode(struct NaClApp *nap, uintptr_t guest_addr,
33 uint8_t *data, size_t size, 33 uint8_t *data, size_t size,
34 const struct NaClValidationMetadata *metadata) { 34 const struct NaClValidationMetadata *metadata) {
35 NaClValidationStatus status = NaClValidationSucceeded; 35 NaClValidationStatus status = NaClValidationSucceeded;
36 struct NaClValidationCache *cache = nap->validation_cache; 36 struct NaClValidationCache *cache = nap->validation_cache;
37 const struct NaClValidatorInterface *validator = nap->validator; 37 const struct NaClValidatorInterface *validator = nap->validator;
38 uint32_t flags = nap->pnacl_mode ? DISABLE_NONTEMPORALS : 0;
38 39
39 if (size < kMinimumCachedCodeSize) { 40 if (size < kMinimumCachedCodeSize) {
40 /* 41 /*
41 * Don't cache the validation of small code chunks for three reasons: 42 * Don't cache the validation of small code chunks for three reasons:
42 * 1) The size of the validation cache will be bounded. Cache entries are 43 * 1) The size of the validation cache will be bounded. Cache entries are
43 * better used for bigger code. 44 * better used for bigger code.
44 * 2) The per-transaction overhead of validation caching is more noticeable 45 * 2) The per-transaction overhead of validation caching is more noticeable
45 * for small code. 46 * for small code.
46 * 3) JITs tend to generate a lot of small code chunks, and JITed code may 47 * 3) JITs tend to generate a lot of small code chunks, and JITed code may
47 * never be seen again. Currently code size is the best mechanism we 48 * never be seen again. Currently code size is the best mechanism we
(...skipping 18 matching lines...) Expand all
66 } 67 }
67 if (nap->validator_stub_out_mode) { 68 if (nap->validator_stub_out_mode) {
68 /* Validation caching is currently incompatible with stubout. */ 69 /* Validation caching is currently incompatible with stubout. */
69 metadata = NULL; 70 metadata = NULL;
70 cache = NULL; 71 cache = NULL;
71 /* In stub out mode, we do two passes. The second pass acts as a 72 /* In stub out mode, we do two passes. The second pass acts as a
72 sanity check that bad instructions were indeed overwritten with 73 sanity check that bad instructions were indeed overwritten with
73 allowable HLTs. */ 74 allowable HLTs. */
74 status = validator->Validate(guest_addr, data, size, 75 status = validator->Validate(guest_addr, data, size,
75 TRUE, /* stub out */ 76 TRUE, /* stub out */
77 flags,
76 FALSE, /* text is not read-only */ 78 FALSE, /* text is not read-only */
77 nap->cpu_features, 79 nap->cpu_features,
78 metadata, 80 metadata,
79 cache); 81 cache);
80 } 82 }
81 if (status == NaClValidationSucceeded) { 83 if (status == NaClValidationSucceeded) {
82 /* Fixed feature CPU mode implies read-only. */ 84 /* Fixed feature CPU mode implies read-only. */
83 int readonly_text = nap->fixed_feature_cpu_mode; 85 int readonly_text = nap->fixed_feature_cpu_mode;
84 status = validator->Validate(guest_addr, data, size, 86 status = validator->Validate(guest_addr, data, size,
85 FALSE, /* do not stub out */ 87 FALSE, /* do not stub out */
88 flags,
86 readonly_text, 89 readonly_text,
87 nap->cpu_features, 90 nap->cpu_features,
88 metadata, 91 metadata,
89 cache); 92 cache);
90 } 93 }
91 return NaClValidateStatus(status); 94 return NaClValidateStatus(status);
92 } 95 }
93 96
94 int NaClValidateCodeReplacement(struct NaClApp *nap, uintptr_t guest_addr, 97 int NaClValidateCodeReplacement(struct NaClApp *nap, uintptr_t guest_addr,
95 uint8_t *data_old, uint8_t *data_new, 98 uint8_t *data_old, uint8_t *data_new,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 NaClLog(LOG_ERROR, 167 NaClLog(LOG_ERROR,
165 "Run sel_ldr in debug mode to ignore validation failure.\n"); 168 "Run sel_ldr in debug mode to ignore validation failure.\n");
166 NaClLog(LOG_ERROR, 169 NaClLog(LOG_ERROR,
167 "Run ncval <module-name> for validation error details.\n"); 170 "Run ncval <module-name> for validation error details.\n");
168 rcode = LOAD_VALIDATION_FAILED; 171 rcode = LOAD_VALIDATION_FAILED;
169 } 172 }
170 } 173 }
171 } 174 }
172 return rcode; 175 return rcode;
173 } 176 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698