summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Gao2018-06-01 18:35:47 -0500
committerJosh Gao2018-07-18 20:11:46 -0500
commit3fa9637e81f5279bb0d931f4e19098c1141f8b73 (patch)
tree68a4d9da329da7481574a75ab06b801e1770e09a /debuggerd
parentc954ec09c527ae1ad758ddd44b178da66c4c35e0 (diff)
downloadplatform-system-core-3fa9637e81f5279bb0d931f4e19098c1141f8b73.tar.gz
platform-system-core-3fa9637e81f5279bb0d931f4e19098c1141f8b73.tar.xz
platform-system-core-3fa9637e81f5279bb0d931f4e19098c1141f8b73.zip
crasher: add close(fileno(FILE*)) and close(dirfd(DIR*)).
Add some cases to trigger fdsan aborts. Test: crasher fdsan_file; crasher fdsan_dir Change-Id: I48152d333dc25900f1c8d8e0f2e8728154643508
Diffstat (limited to 'debuggerd')
-rw-r--r--debuggerd/crasher/crasher.cpp72
1 files changed, 40 insertions, 32 deletions
diff --git a/debuggerd/crasher/crasher.cpp b/debuggerd/crasher/crasher.cpp
index f31337d70..f0fe1d0d9 100644
--- a/debuggerd/crasher/crasher.cpp
+++ b/debuggerd/crasher/crasher.cpp
@@ -183,6 +183,8 @@ static int usage() {
183 fprintf(stderr, " exit call exit(1)\n"); 183 fprintf(stderr, " exit call exit(1)\n");
184 fprintf(stderr, "\n"); 184 fprintf(stderr, "\n");
185 fprintf(stderr, " fortify fail a _FORTIFY_SOURCE check\n"); 185 fprintf(stderr, " fortify fail a _FORTIFY_SOURCE check\n");
186 fprintf(stderr, " fdsan_file close a file descriptor that's owned by a FILE*\n");
187 fprintf(stderr, " fdsan_dir close a file descriptor that's owned by a DIR*\n");
186 fprintf(stderr, " seccomp fail a seccomp check\n"); 188 fprintf(stderr, " seccomp fail a seccomp check\n");
187#if defined(__arm__) 189#if defined(__arm__)
188 fprintf(stderr, " kuser_helper_version call kuser_helper_version\n"); 190 fprintf(stderr, " kuser_helper_version call kuser_helper_version\n");
@@ -236,39 +238,45 @@ noinline int do_action(const char* arg) {
236 238
237 // Actions. 239 // Actions.
238 if (!strcasecmp(arg, "SIGSEGV-non-null")) { 240 if (!strcasecmp(arg, "SIGSEGV-non-null")) {
239 sigsegv_non_null(); 241 sigsegv_non_null();
240 } else if (!strcasecmp(arg, "smash-stack")) { 242 } else if (!strcasecmp(arg, "smash-stack")) {
241 volatile int len = 128; 243 volatile int len = 128;
242 return smash_stack(&len); 244 return smash_stack(&len);
243 } else if (!strcasecmp(arg, "stack-overflow")) { 245 } else if (!strcasecmp(arg, "stack-overflow")) {
244 overflow_stack(nullptr); 246 overflow_stack(nullptr);
245 } else if (!strcasecmp(arg, "nostack")) { 247 } else if (!strcasecmp(arg, "nostack")) {
246 crashnostack(); 248 crashnostack();
247 } else if (!strcasecmp(arg, "exit")) { 249 } else if (!strcasecmp(arg, "exit")) {
248 exit(1); 250 exit(1);
249 } else if (!strcasecmp(arg, "call-null")) { 251 } else if (!strcasecmp(arg, "call-null")) {
250 return crash_null(); 252 return crash_null();
251 } else if (!strcasecmp(arg, "crash") || !strcmp(arg, "SIGSEGV")) { 253 } else if (!strcasecmp(arg, "crash") || !strcmp(arg, "SIGSEGV")) {
252 return crash(42); 254 return crash(42);
253 } else if (!strcasecmp(arg, "abort")) { 255 } else if (!strcasecmp(arg, "abort")) {
254 maybe_abort(); 256 maybe_abort();
255 } else if (!strcasecmp(arg, "assert")) { 257 } else if (!strcasecmp(arg, "assert")) {
256 __assert("some_file.c", 123, "false"); 258 __assert("some_file.c", 123, "false");
257 } else if (!strcasecmp(arg, "assert2")) { 259 } else if (!strcasecmp(arg, "assert2")) {
258 __assert2("some_file.c", 123, "some_function", "false"); 260 __assert2("some_file.c", 123, "some_function", "false");
259 } else if (!strcasecmp(arg, "fortify")) { 261 } else if (!strcasecmp(arg, "fortify")) {
260 char buf[10]; 262 char buf[10];
261 __read_chk(-1, buf, 32, 10); 263 __read_chk(-1, buf, 32, 10);
262 while (true) pause(); 264 while (true) pause();
265 } else if (!strcasecmp(arg, "fdsan_file")) {
266 FILE* f = fopen("/dev/null", "r");
267 close(fileno(f));
268 } else if (!strcasecmp(arg, "fdsan_dir")) {
269 DIR* d = opendir("/dev/");
270 close(dirfd(d));
263 } else if (!strcasecmp(arg, "LOG(FATAL)")) { 271 } else if (!strcasecmp(arg, "LOG(FATAL)")) {
264 LOG(FATAL) << "hello " << 123; 272 LOG(FATAL) << "hello " << 123;
265 } else if (!strcasecmp(arg, "LOG_ALWAYS_FATAL")) { 273 } else if (!strcasecmp(arg, "LOG_ALWAYS_FATAL")) {
266 LOG_ALWAYS_FATAL("hello %s", "world"); 274 LOG_ALWAYS_FATAL("hello %s", "world");
267 } else if (!strcasecmp(arg, "LOG_ALWAYS_FATAL_IF")) { 275 } else if (!strcasecmp(arg, "LOG_ALWAYS_FATAL_IF")) {
268 LOG_ALWAYS_FATAL_IF(true, "hello %s", "world"); 276 LOG_ALWAYS_FATAL_IF(true, "hello %s", "world");
269 } else if (!strcasecmp(arg, "SIGFPE")) { 277 } else if (!strcasecmp(arg, "SIGFPE")) {
270 raise(SIGFPE); 278 raise(SIGFPE);
271 return EXIT_SUCCESS; 279 return EXIT_SUCCESS;
272 } else if (!strcasecmp(arg, "SIGILL")) { 280 } else if (!strcasecmp(arg, "SIGILL")) {
273#if defined(__aarch64__) 281#if defined(__aarch64__)
274 __asm__ volatile(".word 0\n"); 282 __asm__ volatile(".word 0\n");
@@ -280,28 +288,28 @@ noinline int do_action(const char* arg) {
280#error 288#error
281#endif 289#endif
282 } else if (!strcasecmp(arg, "SIGTRAP")) { 290 } else if (!strcasecmp(arg, "SIGTRAP")) {
283 raise(SIGTRAP); 291 raise(SIGTRAP);
284 return EXIT_SUCCESS; 292 return EXIT_SUCCESS;
285 } else if (!strcasecmp(arg, "fprintf-NULL")) { 293 } else if (!strcasecmp(arg, "fprintf-NULL")) {
286 fprintf_null(); 294 fprintf_null();
287 } else if (!strcasecmp(arg, "readdir-NULL")) { 295 } else if (!strcasecmp(arg, "readdir-NULL")) {
288 readdir_null(); 296 readdir_null();
289 } else if (!strcasecmp(arg, "strlen-NULL")) { 297 } else if (!strcasecmp(arg, "strlen-NULL")) {
290 return strlen_null(); 298 return strlen_null();
291 } else if (!strcasecmp(arg, "pthread_join-NULL")) { 299 } else if (!strcasecmp(arg, "pthread_join-NULL")) {
292 return pthread_join(0, nullptr); 300 return pthread_join(0, nullptr);
293 } else if (!strcasecmp(arg, "heap-usage")) { 301 } else if (!strcasecmp(arg, "heap-usage")) {
294 abuse_heap(); 302 abuse_heap();
295 } else if (!strcasecmp(arg, "leak")) { 303 } else if (!strcasecmp(arg, "leak")) {
296 leak(); 304 leak();
297 } else if (!strcasecmp(arg, "SIGSEGV-unmapped")) { 305 } else if (!strcasecmp(arg, "SIGSEGV-unmapped")) {
298 char* map = reinterpret_cast<char*>(mmap(nullptr, sizeof(int), PROT_READ | PROT_WRITE, 306 char* map = reinterpret_cast<char*>(
299 MAP_SHARED | MAP_ANONYMOUS, -1, 0)); 307 mmap(nullptr, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0));
300 munmap(map, sizeof(int)); 308 munmap(map, sizeof(int));
301 map[0] = '8'; 309 map[0] = '8';
302 } else if (!strcasecmp(arg, "seccomp")) { 310 } else if (!strcasecmp(arg, "seccomp")) {
303 set_system_seccomp_filter(); 311 set_system_seccomp_filter();
304 syscall(99999); 312 syscall(99999);
305#if defined(__arm__) 313#if defined(__arm__)
306 } else if (!strcasecmp(arg, "kuser_helper_version")) { 314 } else if (!strcasecmp(arg, "kuser_helper_version")) {
307 return __kuser_helper_version; 315 return __kuser_helper_version;