Commit graph

440 commits

Author SHA1 Message Date
Josh Gao
a70f11331f Merge "crash_dump: make output fd O_APPEND." 2017-02-16 22:43:59 +00:00
Josh Gao
f6ad5851e6 crash_dump: fix typos in error messages.
Bug: http://b/34760032
Bug: http://b/35367169
Test: mm
Change-Id: I45fa002d4ca616a41524583228987ab1197a125e
2017-02-15 17:03:30 -08:00
Josh Gao
8a7e703912 crash_dump: make output fd O_APPEND.
Bug: http://b/35209835
Test: mma
Change-Id: I447e3cfa3361f9c8b4b3335d0abccd1fe4c98e0f
2017-02-15 16:25:27 -08:00
Josh Gao
60515bf9f1 debuggerd_handler: don't use snprintf in handler.
snprintf isn't safe to call in the linker after initialization, because
it uses MB_CUR_MAX which is implemented via pthread_getspecific, which
uses TLS slots shared with libc. If the TLS slots are assigned in a
different order between libc.so and the linker, MB_CUR_MAX will
evaluate to an incorrect value, and lead to snprintf doing bad things.

Switch to __libc_format_buffer.

Bug: http://b/35367169
Test: debuggerd -b `pidof zygote`
Change-Id: I9d315cf63e5f3fd2f4545d6e3f707cdbe94ec606
2017-02-15 12:24:09 -08:00
Josh Gao
2f11a25a48 debuggerd_handler: set PR_SET_DUMPABLE before running crash_dump.
Set and restore PR_SET_DUMPABLE when performing a dump, so that
processes that have it implicitly cleared (e.g. services that acquire
filesystem capabilities) still get crash dumps.

Bug: http://b/35174939
Test: debuggerd -b `pidof surfaceflinger`
Change-Id: Ife933c10086e546726dec12a7efa3f9cedfeea60
2017-02-14 21:19:38 -08:00
Josh Gao
d2069632bd debuggerd_handler: raise capabilities before running crash_dump.
Raise CapInh and CapAmb after forking to exec crash_dump, so that it
can ptrace us.

Bug: http://b/35174939
Test: debuggerd -b `pidof surfaceflinger`
Change-Id: I32567010a3603cfa494aae9dc0e3ce73fb86b590
2017-02-14 14:40:47 -08:00
Josh Gao
91ad653c82 crasher: add a case that uses PR_SET_NO_NEW_PRIVS.
Bug: http://b/34684590
Test: crasher no_new_privs
Change-Id: I400d599116e3f3c27f5ea46d260e288cf900e156
2017-02-14 14:40:47 -08:00
Josh Gao
c3c8c029ec debuggerd_handler: don't use waitpid(..., __WCLONE).
waitpid(..., __WCLONE) fails with ECHILD when passed an explicit PID to
wait for. __WALL and __WCLONE don't seem to be necessary when waiting
for a specific pid, so just pass 0 in the flags instead.

Bug: http://b/35327712
Test: /data/nativetest/debuggerd_test/debuggerd_test32 --gtest_filter="*zombie*"
Change-Id: I3dd7a1bdf7ff35fdfbf631429c089ef4e3172855
2017-02-13 17:01:24 -08:00
Josh Gao
c24cc8a9e5 crash_dump: collect open files before dropping caps.
/proc/<pid>/fd is also limited by ptrace_may_access.

Test: manual inspection of "debuggerd -b `pidof zygote`"
Change-Id: I1a28c21c0438fe8729bd8e041c6b418d6a84c586
2017-02-07 13:36:08 -08:00
Josh Gao
7a0ee64f9d debuggerd_test: improve error when crasher fails to exec.
Bug: http://b/35100742
Test: rm /system/bin/crasher && /data/nativetest/debugerd_test/debuggerd_test32
Change-Id: I02faec3b7f7ef62bb8a2ac2af730506e3d28e03e
2017-02-07 13:36:08 -08:00
Josh Gao
a7d7eb6d2a debuggerd_test: fix crasher path.
https://android-review.googlesource.com/#/c/331200 moved crasher to
using soong, which changed its location from /system/xbin/crasher to
/system/bin/crasher.

Bug: http://b/35100742
Test: /data/nativetest/debuggerd_test/debuggerd_test32
Test: /data/nativetest64/debuggerd_test/debuggerd_test64
Change-Id: I16a2050b257277023773cc0c960b5ab36e0c7cd4
2017-02-07 13:13:48 -08:00
Josh Gao
347164cc59 crash_dump: read /proc/<pid>/maps before dropping capabilities.
Reading /proc/<pid>/maps does a ptrace_may_access check, which will
fail if we have fewer capabilities than the target, even if we've
already ptraced it.

Bug: http://b/35070339
Test: debuggerd -b `pidof zygote`
Change-Id: I984a061022bd945a7950b88f6d579e1bd735e893
2017-02-07 12:35:51 -08:00
Josh Gao
54ef57d0b8 debuggerd_handler: fix prctl return value check.
Fixed this when I tested on internal, but failed to copy the fix over
when submitting to AOSP.

Bug: http://b/35070339
Test: `adb bugreport` on angler
Change-Id: Ib84d212e5f890958cd21f5c018fbc6f368138d1e
2017-02-06 21:10:48 -08:00
Josh Gao
279cb8b39a Merge changes from topic 'debuggerd_ambient'
* changes:
  debuggerd_handler: don't use clone(..., SIGCHLD, ...)
  crash_dump: drop capabilities after we ptrace attach.
  crash_dump: use /proc/<pid> fd to check tid process membership.
  debuggerd_handler: raise ambient capset before execing.
  Revert "Give crash_dump CAP_SYS_PTRACE."
2017-02-06 18:37:55 +00:00
Josh Gao
b3ee52e4d0 debuggerd_handler: don't use clone(..., SIGCHLD, ...)
Processes that handle SIGCHLD can race with the crash handler to wait
on the crash_dump process. Use clone flags that cause the forked
child's death to not be reported via SIGCHLD, and don't bail out of
dumping when waitpid returns ECHILD (in case another thread is already
in a waitpid(..., __WALL))

Note that the use of waitid was switched to waitpid, because waitid
doesn't support __WCLONE until kernel version 4.7.

Bug: none
Test: "debuggerd -b `pidof zygote64`" a few times (failed roughly 50%
      of the time previously)
Change-Id: Ia41a26a61f13c6f9aa85c4c2f88aef8d279d35ad
2017-02-02 13:54:39 -08:00
Josh Gao
85bcaf68d3 crash_dump: drop capabilities after we ptrace attach.
Bug: http://b/34853272
Test: debuggerd -b `pidof system_server`
Test: debuggerd -b `pidof zygote`
Change-Id: Ic1e1a4b0eb1f561621800cd4cc9a5b848fc5ffd8
2017-02-02 13:54:38 -08:00
Josh Gao
fe90276aee crash_dump: use /proc/<pid> fd to check tid process membership.
Bug: http://b/34759490
Test: /data/nativetest/debuggerd_test/debuggerd_test32
Test: debuggerd -b `pidof system_server`
Test: debuggerd -b `pidof zygote`
Change-Id: I627692b44977335a9568cd765ad28205f0a61327
2017-02-02 13:54:38 -08:00
Josh Gao
7ae426c731 debuggerd_handler: raise ambient capset before execing.
Raise the ambient capability set to match CapEff so that crash_dump can
inherit all of the capabilities of the dumped process to be able to
ptrace. Note that selinux will prevent crash_dump from actually use
any of the capabilities.

Bug: http://b/34853272
Test: debuggerd -b `pidof system_server`
Test: debuggerd -b `pidof zygote`
Change-Id: I1fe69eff54c1c0a5b3ec63f6fa504b2681c47a88
2017-02-02 13:54:38 -08:00
Elliott Hughes
f4ae6203a9 Merge "Better seccomp/kuser_helper diagnostics from debuggerd." 2017-02-02 17:37:25 +00:00
Elliott Hughes
0ba535976f Better seccomp/kuser_helper diagnostics from debuggerd.
Also switch to Android.bp for crasher.

Bug: http://b/34629282 (seccomp)
Bug: http://b/34705831 (seccomp)
Bug: http://b/34884086 (kuser_helpers)
Test: manual
Change-Id: I8ee79c635518faeba751742919af69a505b5e3e1
2017-02-01 18:43:03 -08:00
Josh Gao
6462bb41e0 debuggerd_handler: add and use fatal_errno.
Bug: none
Test: mma
Change-Id: I24d913abdbe74f9463feda78f7817ca8b92af9cc
2017-01-31 14:59:05 -08:00
Josh Gao
1e4afb52c5 debuggerd: fix debuggerd <pid>
Bug: none
Test: `debuggerd mediaserver`
Change-Id: Ibd7bbddb92a99ce49622c0ecc9329a3723f2085d
2017-01-30 17:58:04 -08:00
Josh Gao
b53f903cf1 debuggerd: fix debuggerd -b <pid>
Dump all of the threads when using `debuggerd -b`.

Bug: http://b/34719257
Test: `debuggerd -b mediaserver`
Change-Id: I2f57100985e5b0c2bf019482ba9feff31921692f
2017-01-30 17:58:04 -08:00
Josh Gao
4ed00c8d73 debuggerd_handler: improve nonfatal signal message.
"Fatal signal 35 (???)" -> "Requested dump for"

Bug: http://b/34809044
Test: debuggerd -b $$
Change-Id: I9ece0ee1117203d30142b843973ed7e5435e21da
2017-01-30 17:58:04 -08:00
Josh Gao
e5288f292a debuggerd_handler: remove PR_SET_DUMPABLE check.
crash_dump has CAP_SYS_PTRACE and this was never obeyed by debuggerd.

Change-Id: Ifee5e94b97b1f6440ad0be79758f0db2d2aaba2e
2017-01-26 15:08:18 -08:00
Josh Gao
7e14d020f1 debuggerd_handler: don't dump PR_NO_NEW_PRIVS processes.
We can't do an selinux transition when this is on.

Bug: http://b/34472671
Test: logcat -c; debuggerd `pidof media.codec`; logcat
Change-Id: Ie6c1832ab838df48879c32a86126862de9a15420
2017-01-25 11:16:03 -08:00
Josh Gao
529b3066d5 debuggerd_handler: don't resend nonfatal signals when not dumping.
Bug: http://b/34516140
Test: debuggerd -b `pidof surfaceflinger`
Change-Id: I0275ffca24bf4840e264eaa4b79611e2404edfb0
2017-01-25 11:15:01 -08:00
Josh Gao
0a37901b9f crash_dump: properly dump when we can't talk to tombstoned.
Bug: http://b/32466479
Test: stop tombstoned; logcat -c; crasher; logcat
Change-Id: I16c010cc1865b4e1db8d2b85c904a2e074f28f1f
2017-01-24 15:22:43 -08:00
Vijay Venkatraman
5fe1cebe7c Merge "Replaced include log/logger.h with log/log.h in debuggerd" 2017-01-24 19:07:30 +00:00
Vijay Venkatraman
a95acea5bf Replaced include log/logger.h with log/log.h in debuggerd
Test: Compile debuggerd
Change-Id: I33d12708993bd6818907b8cbb0a7a40672ad320d
2017-01-23 20:11:51 -08:00
Josh Gao
8498016b81 tombstoned: silence spurious error messages.
Bug: none
Test: booted after deleting /data/tombstones/*
Test: crasher creates a tombstone
Change-Id: I8b3e8a3b521952412ebc955b2437bf8150220c16
2017-01-23 16:01:14 -08:00
Josh Gao
0ad5107e51 Actually don't start tombstoned until /data is mounted.
Bug: http://b/34461270
Test: boot is actually faster
Test: tombstoned still started by init
Change-Id: I4976abef108bbb6fad264f9b68cbc1fba711085b
2017-01-23 16:01:14 -08:00
Josh Gao
4decbe0d6c debuggerd_handler: add SIGSYS to the list of handled signals.
Bug: http://b/34586922
Test: kill -SYS $$
Change-Id: I31dadb9c65141d0c5556cc7256439e0a8d1519ab
2017-01-23 16:01:14 -08:00
Josh Gao
fca7ca3585 debuggerd_handler: properly crash when PR_GET_DUMPABLE is 0.
Actually exit when receiving a signal via kill(2) or raise(2) and
PR_GET_DUMPABLE is 0.

Bug: none
Test: /data/nativetest/debuggerd_test/debuggerd_test32
Test: /data/nativetest64/bionic-unit-tests/bionic-unit-tests --gtest_filter=pthread_DeathTest.pthread_mutex_lock_null_64
Change-Id: I833a2a34238129237bd9f953959ebda51d8d04d7
2017-01-23 14:13:36 -08:00
Josh Gao
7c6e3133f5 crash_dump: set a watchdog timer.
PTRACE_DETACH is only necessary if the process is in group-stop state,
the tracer exiting is sufficient to detach and resume tracees.

Using this, set a 5 second timer with alarm(2) that just kills us, to
avoid leaving processes stopped.

Bug: http://b/34472671
Test: debuggerd_test
Test: crasher + manually inserting a 10 second sleep into crash_dump
Change-Id: Iacaa796f79037aa1585f3f2159abe45ef0069311
2017-01-23 11:39:31 -08:00
Josh Gao
122479f4a0 crash_dump: switch to PTRACE_SEIZE.
ptrace(PTRACE_ATTACH) does not immediately put the traced process in a
stopped state. If we manage to call PTRACE_CONT on it before it
finishes, we'll fail. Switch to using PTRACE_SEIZE and PTRACE_INTERRUPT
to guarantee that the target stops immediately.

This also has the advantage of never putting the process in group-stop
state, which means if we exit prematurely (e.g. if we crash during
stack unwinding), the target process will be resumed without any
intervention needed.

Bug: http://b/34472671
Test: while true; do debuggerd -b `pidof audioserver`; done
Change-Id: I7549f67489646cf300b8c9aa8c735e5e897806ef
2017-01-23 11:34:49 -08:00
Josh Gao
575941115e crash_dump: clear the default crash handlers.
crash_dump is a dynamic executable that gets the default crash dumping
handlers set by the linker. Turn them off to prevent crash_dump from
dumping itself.

Bug: http://b/34472671
Test: inserted an abort into crash_dump
Change-Id: Ic9d708805ad47afbb2a9ff37e2ca059f23f421de
2017-01-23 11:34:49 -08:00
Josh Gao
d20d687de5 crash_dump: remove extra log.
We're already aborting via LOG(FATAL), there's no reason to log again.

Bug: none
Test: mma
Change-Id: I96cb09b716b19381d6a6931048827ef45f87170b
2017-01-23 11:34:49 -08:00
Josh Gao
b64dd85c94 debuggerd_handler: actually wait for pseudothread to exit.
Occasionally, the pseudothread wouldn't exit in time after unlocking
the mutex to get crash_dump to proceed, resulting in spurious error
messages. Instead of using a mutex to emulate pthread_join, just
implement it correctly.

Bug: http://b/34472671
Test: debuggerd_test
Change-Id: I5c2658a84e9407ed8cc0ef2ad0fb648c388b7ad1
2017-01-23 11:34:49 -08:00
Treehugger Robot
b479a5002e Merge "init: don't start tombstoned until /data is mounted." 2017-01-20 22:13:38 +00:00
Josh Gao
42a0fed78b init: don't start tombstoned until /data is mounted.
When vold mounts the encrypted /data partition, it first checks for and
kills processes that have open fds to the tmpfs placeholder at /data.
This resulted in a 20 second boot-time regression (vold's timeout period)
when tombstoned was started before vold.

Bug: http://b/34461270
Test: boot is faster, no messages from vold in console spew
Test: tombstoned still started by init
Change-Id: Ib5e9ddb05f40c9da852f00e103861c6ff2d94888
2017-01-20 13:18:51 -08:00
Josh Gao
ac0403b1e5 Merge "crash_dump: don't abort if we fail to attach a sibling." 2017-01-20 21:02:30 +00:00
Josh Gao
42fd74bd1f crash_dump: don't abort if we fail to attach a sibling.
A TOCTOU race can occur between listing threads and attaching them.
Don't abort and leave the process in a stopped state when this happens.

Bug: http://b/34472671
Test: while true; do debuggerd -b `pidof audioserver`; done
Change-Id: Ib1632c3423fddf506b5c7874223c82fada78a85e
2017-01-20 12:55:07 -08:00
George Burgess IV
7008c8484d Fix a call to openat with incorrect arguments
Caught by running clang-FORTIFY over Android.

Bug: None
Test: Builds
Change-Id: If138c4bbb7f5fb40bbb20e24adbb25a6ef1286ac
2017-01-19 13:33:52 -08:00
Josh Gao
cbe70cb0a8 debuggerd: advance our amazing bet.
Remove debuggerd in favor of a helper process that gets execed by
crashing processes.

Bug: http://b/30705528
Test: debuggerd_test
Change-Id: I9906c69473989cbf7fe5ea6cccf9a9c563d75906
2017-01-17 13:57:57 -08:00
Mark Salyzyn
51c33b7011 liblog: use log/log.h for ALOG macros
Test: compile
Bug: 34250038
Change-Id: I0f56c563871f377c03380498cd867b916892f1dc
2017-01-12 15:44:06 -08:00
Mark Salyzyn
30f991f251 liblog: use log/log.h when utilizing ALOG macros
Test: compile
Bug: 30465923
Change-Id: Id6d76510819ebd88c3f5003d00d73a0dbe85e943
2017-01-11 09:31:15 -08:00
Elliott Hughes
400628aeac Improve crasher.
Make it behave better in our typical use cases and support more of the kinds
of crash we want to document.

Bug: http://b/28746168
Test: crasher
Change-Id: Ifbc3dfb042f6055568244c921f4abe1ea554cec4
2016-12-14 17:33:46 -08:00
Richard Uhler
3ff028c7db Merge "debuggerd: Dump list of open files on process crash."
am: b675f7cd32

Change-Id: Iec231fc7eb57fa2c51aabc0fb75b4a09c47004cd
2016-11-30 09:18:57 +00:00
Treehugger Robot
b675f7cd32 Merge "debuggerd: Dump list of open files on process crash." 2016-11-30 07:53:09 +00:00