OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 Google Inc. All Rights Reserved. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 | |
15 // The C++ implementation of the memory interceptors, intended to work on win64, | |
16 // unlike the win32 implementation, written (generated) in pure assembly. | |
17 // This implementation provides less functions than the original win32 one, | |
18 // as it's intended to be used outside of Syzygy. | |
19 | |
20 #include "syzygy/agent/asan/error_info.h" | |
21 #include "syzygy/agent/asan/rtl_utils.h" | |
22 #include "syzygy/agent/asan/runtime.h" | |
23 #include "syzygy/agent/asan/shadow.h" | |
24 | |
25 // The template function that performs the checks. | |
26 // @param access_size Access size in bytes. | |
27 // @param heap_size The virtual address space size limit in bytes. | |
28 // It's 8 TB for Win7 and Win8 and 128 TB for Win8.1+. | |
29 // @param access_mode The access mode, which can be any of AccessMode values, | |
30 // allthough this file only exports the probes for read and write accesses. | |
31 // @param addr The address being accessed. | |
32 template<size_t access_size, size_t heap_size, | |
33 agent::asan::AccessMode access_mode> | |
34 void asan_check(const void* addr) { | |
35 using namespace agent::asan; | |
36 if (reinterpret_cast<uintptr_t>(addr) >= heap_size || | |
37 !AsanRuntime::runtime()->shadow()->IsRangeAccessible(addr, access_size)) { | |
38 CONTEXT ctx = {}; | |
39 ::RtlCaptureContext(&ctx); | |
40 AsanContext asan_ctx = {}; | |
41 ContextToAsanContext(ctx, &asan_ctx); | |
42 ReportBadMemoryAccess(addr, access_mode, access_size, asan_ctx); | |
43 } | |
44 } | |
45 | |
46 // A few macros to instantiate 'asan_check' and export the instantiations | |
47 // with appropriate names. | |
48 | |
49 #define EXPORT_INTERCEPTOR_READ(access_size, suffix, heap_size) \ | |
50 void asan_check_##access_size##_byte_read_access_no_flags_##suffix( \ | |
51 const void* addr) { \ | |
52 return asan_check<access_size, heap_size, \ | |
53 agent::asan::ASAN_READ_ACCESS>(addr); \ | |
54 } \ | |
55 void asan_check_##access_size##_byte_read_access_##suffix(const void* addr) { \ | |
56 return asan_check<access_size, heap_size, \ | |
57 agent::asan::ASAN_READ_ACCESS>(addr); \ | |
58 } | |
59 | |
60 #define EXPORT_INTERCEPTOR_WRITE(access_size, suffix, heap_size) \ | |
61 void asan_check_##access_size##_byte_write_access_no_flags_##suffix( \ | |
62 const void* addr) { \ | |
63 return asan_check<access_size, heap_size, \ | |
64 agent::asan::ASAN_WRITE_ACCESS>(addr); \ | |
65 } \ | |
66 void asan_check_##access_size##_byte_write_access_##suffix(const void* addr) { \ | |
67 return asan_check<access_size, heap_size, \ | |
68 agent::asan::ASAN_WRITE_ACCESS>(addr); \ | |
69 } | |
70 | |
71 #define EXPORT_INTERCEPTOR(access_size, suffix, heap_size) \ | |
72 EXPORT_INTERCEPTOR_READ(access_size, suffix, heap_size) \ | |
73 EXPORT_INTERCEPTOR_WRITE(access_size, suffix, heap_size) | |
74 | |
75 #define EXPORT_INTERCEPTORS_ALL_SIZES(suffix, heap_size) \ | |
Sébastien Marchand
2016/09/13 16:03:09
One more comment, I don't think that |heap_size| i
| |
76 EXPORT_INTERCEPTOR(1, suffix, heap_size) \ | |
77 EXPORT_INTERCEPTOR(2, suffix, heap_size) \ | |
78 EXPORT_INTERCEPTOR(4, suffix, heap_size) \ | |
79 EXPORT_INTERCEPTOR(8, suffix, heap_size) \ | |
80 EXPORT_INTERCEPTOR(10, suffix, heap_size) \ | |
81 EXPORT_INTERCEPTOR(16, suffix, heap_size) \ | |
82 EXPORT_INTERCEPTOR(32, suffix, heap_size) | |
83 | |
84 extern "C" { | |
85 void asan_no_check() { return; } | |
Sébastien Marchand
2016/09/13 15:48:16
I don't think that we want to export the function
| |
86 void asan_string_no_check() { return; } | |
87 void* asan_shadow_references[] = { nullptr }; | |
88 EXPORT_INTERCEPTORS_ALL_SIZES(8tb, static_cast<size_t>(8) << 40) | |
89 EXPORT_INTERCEPTORS_ALL_SIZES(128tb, static_cast<size_t>(128) << 40) | |
90 } | |
OLD | NEW |