|
1 // All rights reserved. |
|
2 // |
|
3 // Redistribution and use in source and binary forms, with or without |
|
4 // modification, are permitted provided that the following conditions are |
|
5 // met: |
|
6 // |
|
7 // * Redistributions of source code must retain the above copyright |
|
8 // notice, this list of conditions and the following disclaimer. |
|
9 // * Redistributions in binary form must reproduce the above |
|
10 // copyright notice, this list of conditions and the following disclaimer |
|
11 // in the documentation and/or other materials provided with the |
|
12 // distribution. |
|
13 // * Neither the name of Google Inc. nor the names of its |
|
14 // contributors may be used to endorse or promote products derived from |
|
15 // this software without specific prior written permission. |
|
16 // |
|
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE// |
|
28 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
29 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
30 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
31 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
32 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
33 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
34 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
35 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
36 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
37 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
38 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
39 |
|
40 #include <stdlib.h> |
|
41 #include <unistd.h> |
|
42 |
|
43 #include <string> |
|
44 |
|
45 #include "breakpad_googletest_includes.h" |
|
46 #include "common/using_std_string.h" |
|
47 #include "google_breakpad/processor/basic_source_line_resolver.h" |
|
48 #include "google_breakpad/processor/call_stack.h" |
|
49 #include "google_breakpad/processor/code_module.h" |
|
50 #include "google_breakpad/processor/code_modules.h" |
|
51 #include "google_breakpad/processor/minidump.h" |
|
52 #include "google_breakpad/processor/minidump_processor.h" |
|
53 #include "google_breakpad/processor/process_state.h" |
|
54 #include "google_breakpad/processor/stack_frame.h" |
|
55 #include "google_breakpad/processor/symbol_supplier.h" |
|
56 |
|
57 namespace google_breakpad { |
|
58 class MockMinidump : public Minidump { |
|
59 public: |
|
60 MockMinidump() : Minidump("") { |
|
61 } |
|
62 |
|
63 MOCK_METHOD0(Read, bool()); |
|
64 MOCK_CONST_METHOD0(path, string()); |
|
65 MOCK_CONST_METHOD0(header, const MDRawHeader*()); |
|
66 MOCK_METHOD0(GetThreadList, MinidumpThreadList*()); |
|
67 }; |
|
68 } |
|
69 |
|
70 namespace { |
|
71 |
|
72 using google_breakpad::BasicSourceLineResolver; |
|
73 using google_breakpad::CallStack; |
|
74 using google_breakpad::CodeModule; |
|
75 using google_breakpad::MinidumpProcessor; |
|
76 using google_breakpad::MinidumpThreadList; |
|
77 using google_breakpad::MinidumpThread; |
|
78 using google_breakpad::MockMinidump; |
|
79 using google_breakpad::ProcessState; |
|
80 using google_breakpad::SymbolSupplier; |
|
81 using google_breakpad::SystemInfo; |
|
82 |
|
83 class TestSymbolSupplier : public SymbolSupplier { |
|
84 public: |
|
85 TestSymbolSupplier() : interrupt_(false) {} |
|
86 |
|
87 virtual SymbolResult GetSymbolFile(const CodeModule *module, |
|
88 const SystemInfo *system_info, |
|
89 string *symbol_file); |
|
90 |
|
91 virtual SymbolResult GetSymbolFile(const CodeModule *module, |
|
92 const SystemInfo *system_info, |
|
93 string *symbol_file, |
|
94 string *symbol_data); |
|
95 |
|
96 virtual SymbolResult GetCStringSymbolData(const CodeModule *module, |
|
97 const SystemInfo *system_info, |
|
98 string *symbol_file, |
|
99 char **symbol_data); |
|
100 |
|
101 virtual void FreeSymbolData(const CodeModule *module) { } |
|
102 // When set to true, causes the SymbolSupplier to return INTERRUPT |
|
103 void set_interrupt(bool interrupt) { interrupt_ = interrupt; } |
|
104 |
|
105 private: |
|
106 bool interrupt_; |
|
107 }; |
|
108 |
|
109 SymbolSupplier::SymbolResult TestSymbolSupplier::GetSymbolFile( |
|
110 const CodeModule *module, |
|
111 const SystemInfo *system_info, |
|
112 string *symbol_file) { |
|
113 |
|
114 if (interrupt_) { |
|
115 return INTERRUPT; |
|
116 } |
|
117 |
|
118 return NOT_FOUND; |
|
119 } |
|
120 |
|
121 SymbolSupplier::SymbolResult TestSymbolSupplier::GetCStringSymbolData( |
|
122 const CodeModule *module, |
|
123 const SystemInfo *system_info, |
|
124 string *symbol_file, |
|
125 char **symbol_data) { |
|
126 return GetSymbolFile(module, system_info, symbol_file); |
|
127 } |
|
128 |
|
129 SymbolSupplier::SymbolResult TestSymbolSupplier::GetSymbolFile( |
|
130 const CodeModule *module, |
|
131 const SystemInfo *system_info, |
|
132 string *symbol_file, |
|
133 string *symbol_data) { |
|
134 return GetSymbolFile(module, system_info, symbol_file); |
|
135 } |
|
136 |
|
137 TEST(ExploitabilityTest, TestWindowsEngine) { |
|
138 TestSymbolSupplier supplier; |
|
139 BasicSourceLineResolver resolver; |
|
140 MinidumpProcessor processor(&supplier, &resolver, true); |
|
141 ProcessState state; |
|
142 |
|
143 string minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") + |
|
144 "/src/processor/testdata/ascii_read_av.dmp"; |
|
145 ASSERT_EQ(processor.Process(minidump_file, &state), |
|
146 google_breakpad::PROCESS_OK); |
|
147 ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH, |
|
148 state.exploitability()); |
|
149 |
|
150 minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") + |
|
151 "/src/processor/testdata/ascii_read_av_block_write.dmp"; |
|
152 ASSERT_EQ(processor.Process(minidump_file, &state), |
|
153 google_breakpad::PROCESS_OK); |
|
154 ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH, |
|
155 state.exploitability()); |
|
156 |
|
157 minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") + |
|
158 "/src/processor/testdata/ascii_read_av_clobber_write.dmp"; |
|
159 ASSERT_EQ(processor.Process(minidump_file, &state), |
|
160 google_breakpad::PROCESS_OK); |
|
161 ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH, |
|
162 state.exploitability()); |
|
163 |
|
164 minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") + |
|
165 "/src/processor/testdata/ascii_read_av_conditional.dmp"; |
|
166 ASSERT_EQ(processor.Process(minidump_file, &state), |
|
167 google_breakpad::PROCESS_OK); |
|
168 ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH, |
|
169 state.exploitability()); |
|
170 |
|
171 minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") + |
|
172 "/src/processor/testdata/ascii_read_av_then_jmp.dmp"; |
|
173 ASSERT_EQ(processor.Process(minidump_file, &state), |
|
174 google_breakpad::PROCESS_OK); |
|
175 ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH, |
|
176 state.exploitability()); |
|
177 |
|
178 minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") + |
|
179 "/src/processor/testdata/ascii_read_av_xchg_write.dmp"; |
|
180 ASSERT_EQ(processor.Process(minidump_file, &state), |
|
181 google_breakpad::PROCESS_OK); |
|
182 ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH, |
|
183 state.exploitability()); |
|
184 |
|
185 minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") + |
|
186 "/src/processor/testdata/ascii_write_av.dmp"; |
|
187 ASSERT_EQ(processor.Process(minidump_file, &state), |
|
188 google_breakpad::PROCESS_OK); |
|
189 ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH, |
|
190 state.exploitability()); |
|
191 |
|
192 minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") + |
|
193 "/src/processor/testdata/ascii_write_av_arg_to_call.dmp"; |
|
194 ASSERT_EQ(processor.Process(minidump_file, &state), |
|
195 google_breakpad::PROCESS_OK); |
|
196 ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH, |
|
197 state.exploitability()); |
|
198 |
|
199 minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") + |
|
200 "/src/processor/testdata/null_read_av.dmp"; |
|
201 ASSERT_EQ(processor.Process(minidump_file, &state), |
|
202 google_breakpad::PROCESS_OK); |
|
203 ASSERT_EQ(google_breakpad::EXPLOITABILITY_NONE, |
|
204 state.exploitability()); |
|
205 |
|
206 minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") + |
|
207 "/src/processor/testdata/null_write_av.dmp"; |
|
208 ASSERT_EQ(processor.Process(minidump_file, &state), |
|
209 google_breakpad::PROCESS_OK); |
|
210 ASSERT_EQ(google_breakpad::EXPLOITABILITY_NONE, |
|
211 state.exploitability()); |
|
212 |
|
213 minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") + |
|
214 "/src/processor/testdata/stack_exhaustion.dmp"; |
|
215 ASSERT_EQ(processor.Process(minidump_file, &state), |
|
216 google_breakpad::PROCESS_OK); |
|
217 ASSERT_EQ(google_breakpad::EXPLOITABILITY_NONE, |
|
218 state.exploitability()); |
|
219 |
|
220 minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") + |
|
221 "/src/processor/testdata/exec_av_on_stack.dmp"; |
|
222 ASSERT_EQ(processor.Process(minidump_file, &state), |
|
223 google_breakpad::PROCESS_OK); |
|
224 ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH, |
|
225 state.exploitability()); |
|
226 |
|
227 minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") + |
|
228 "/src/processor/testdata/write_av_non_null.dmp"; |
|
229 ASSERT_EQ(processor.Process(minidump_file, &state), |
|
230 google_breakpad::PROCESS_OK); |
|
231 ASSERT_EQ(google_breakpad::EXPLOITABLITY_MEDIUM, |
|
232 state.exploitability()); |
|
233 |
|
234 minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") + |
|
235 "/src/processor/testdata/read_av_non_null.dmp"; |
|
236 ASSERT_EQ(processor.Process(minidump_file, &state), |
|
237 google_breakpad::PROCESS_OK); |
|
238 ASSERT_EQ(google_breakpad::EXPLOITABILITY_LOW, |
|
239 state.exploitability()); |
|
240 |
|
241 minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") + |
|
242 "/src/processor/testdata/read_av_clobber_write.dmp"; |
|
243 ASSERT_EQ(processor.Process(minidump_file, &state), |
|
244 google_breakpad::PROCESS_OK); |
|
245 ASSERT_EQ(google_breakpad::EXPLOITABILITY_LOW, |
|
246 state.exploitability()); |
|
247 |
|
248 minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") + |
|
249 "/src/processor/testdata/read_av_conditional.dmp"; |
|
250 ASSERT_EQ(processor.Process(minidump_file, &state), |
|
251 google_breakpad::PROCESS_OK); |
|
252 ASSERT_EQ(google_breakpad::EXPLOITABILITY_LOW, |
|
253 state.exploitability()); |
|
254 } |
|
255 } |