Commit graph

28 commits

Author SHA1 Message Date
Josh Gao
2b22ae132f tombstoned: don't generate tombstones for native backtraces.
Previously, if an intercept ends before we ask for a file descriptor
when doing a backtrace, we'll create a tombstone file instead.

Bug: http://b/114139908
Bug: http://b/115349586
Test: debuggerd_test32
Change-Id: I23c7bb8ae5a982a4374a862d0a4f17bee03eb1d9
2018-09-14 14:06:47 -07:00
Josh Gao
f5974aedc4 tombstoned: make missing O_TMPFILE workaround actually work around.
We can't actually link an unlinked file back onto disk if it wasn't
opened with O_TMPFILE. Switch to using a temporary filename instead.

Bug: http://b/77729983
Test: agampe
Change-Id: I1970497114f0056065a1ba65f6358f08b51ec551
2018-05-03 16:05:32 -07:00
Josh Gao
28f8cf0f97 tombstoned: don't bail out if we fail to unlink a file that isn't there.
Test: crasher with no tombstones
Change-Id: I20e0537a347dd1f83877150ab13f53441dd65d95
2018-05-03 14:31:08 -07:00
Josh Gao
48383c806a tombstoned: don't create tombstones for failed dumps.
Instead of creating tombstone FDs in place and passing them out to
crash_dump directly, create them as O_TMPFILEs and link them into place
when crash_dump reports success, to avoid creating empty tombstones
in cases like an aborting thread racing with another thread that
manages to cleanly exit_group before the dump finishes.

Bug: http://b/77729983
Test: debuggerd_test
Test: adb shell 'for x in `seq 0 50`; do crasher; done'
Change-Id: I31ce4fd4a524abf8bde57152450209483d9d0ba9
2018-04-19 14:33:18 -07:00
Josh Gao
ce9cc4e428 tombstoned: fix another call to evconnlistener_new.
Apply the same fix from c2e98f63 to intercept_manager.cpp.

Bug: http://b/64543673
Test: debuggerd_test
Change-Id: Ibfb919e059fa62f8336cfc1426d03ef015590136
2017-09-22 18:00:35 -07:00
Narayan Kamath
c2e98f6340 tombstoned: Fix calls to evconnlistener_new.
The order of arguments is wrong - we're passing flags=static_cast<unsigned>(-1)
and backlog=LEV_OPT_CLOSE_ON_FREE (which is 2).

On versions of libevent prior to 2.1.8, this ends up accidentally setting
OPT_LEAVE_SOCKETS_BLOCKING, OPT_CLOSE_ON_EXEC, OPT_REUSABLE and OPT_THREADSAFE
and limiting our backlog to two. These unintentional changes are relatively
benign; we never make our sockets block, we never exec, we never reuse
sockets and the additional locking overhead should be negligible. The
backlog of two might be a problem in theory, but there haven't been any
reports of issues caused by it.

Things get worse on 2.1.8 - that version introduces several new flags,
one of which is OPT_DISABLED. This disables the new listener by default,
which means that our event loop returns early because it has no active listeners
for any of its events.

Bug: 64543673
Test: Manual.

Change-Id: I9954bc7fe1af761de1a950d935dd2e6ce7e2c5f5
2017-09-13 14:15:57 +01:00
Elliott Hughes
3e8d923276 Merge "Allow configuration of the number of tombstones." 2017-06-27 20:57:08 +00:00
Elliott Hughes
35bb6d2a89 Allow configuration of the number of tombstones.
Bug: http://b/62810514
Test: altered the property, got more tombstones
Change-Id: Iba8089915fa715658d2dfecb076c6a61321243bd
2017-06-26 14:00:00 -07:00
Narayan Kamath
111f351762 Merge "tombstoned: Improve message on java trace completion." 2017-06-23 08:12:51 +00:00
Narayan Kamath
79dd143e5f tombstoned: Improve message on java trace completion.
For java traces, log the kind of dump as well as the PID of the
completed dump. This makes it easier to correlate dump requests with the
actual file they're written to.

Sample log statement:
E /system/bin/tombstoned: Traces for pid 4737 written to: /data/anr/trace_00

The message for native traces / tombstones remains unchanged because
several tools parse it.

Test: manual
Bug: 32064548

Change-Id: I7b3792dd5ae312ee0bc055c22ec3f7c747152072
2017-06-22 11:04:33 +01:00
Narayan Kamath
b123220dd6 tombstoned: change path for traces from "anr_" to "trace_"
The only case where tombstoned creates files for java traces is
when the process is signalled "by hand" using "shell kill -3", or
by the program itself. Such traces do not correspond to an ANR, so
name those files "trace_XX".

When dumpstate / system_server want to dump java traces, they set up
a tombstoned intercept and manage the lifetime of any associated file
that themselves.

Bug: 32064548
Test: manual, debuggerd_test
Change-Id: I97006ec7c0cd35de4b9564f535e77af846cc3891
2017-06-21 18:00:09 +01:00
Treehugger Robot
87f5432f52 Merge "tombstoned: log where we're writing the tombstone." 2017-06-13 02:47:34 +00:00
Josh Gao
cb68a0317d tombstoned: log where we're writing the tombstone.
Make it easy to find out where a specific crash's tombstone was written
to by adding a log.

Bug: http://b/62268830
Test: crasher
Change-Id: I1961dfb19f76a42a8448ebafd4be153b73cb6800
2017-06-12 21:00:59 +00:00
Narayan Kamath
ca5e908dd6 tombstoned: turn on java trace support + unit tests.
The SELinux changes that this depends on have now landed.

This change also adds a few lower level unit tests of intercept
functionality.

Test: make; debuggerd_test
Change-Id: I0be5e85e7097e26b71db269c9ed92d9b438bfb28
2017-06-07 18:57:54 +01:00
Narayan Kamath
a73df601b7 tombstoned: allow intercepts for java traces.
All intercept requests and crash dump requests must now specify a
dump_type, which can be one of kDebuggerdNativeBacktrace,
kDebuggerdTombstone or kDebuggerdJavaBacktrace. Each process can have
only one outstanding intercept registered at a time.

There's only one non-trivial change in this changeset; and that is
to crash_dump. We now pass the type of dump via a command line
argument instead of inferring it from the (resent) signal, this allows
us to connect to tombstoned before we wait for the signal as the
protocol requires.

Test: debuggerd_test

Change-Id: I189b215acfecd08ac52ab29117e3465da00e3a37
2017-05-31 10:35:32 +01:00
Narayan Kamath
2d377cd688 tombstoned: Add a shared library version of libtombstoned_client...
.. for ART and the frameworks to link against. In the new stack dumping
scheme (see related bug), the Java runtime will communicate with
tombstoned in order to obtain a FD to which it can write its traces.

Also move things around to separate headers that are private
implementation details from headers that constitute the public debuggerd
API. There are currently only three such headers :

- tombstoned/tombstoned.h
- debuggerd/client.h
- debuggerd/handler.h

Bug: 32064548
Test: make

Change-Id: If1b8578550e373d84828b180bbe585f1088d1aa3
2017-05-22 16:55:21 +01:00
Narayan Kamath
922f6b22fc tombstoned: Support java trace dumps.
The changes here involve :
- Creating and opening a new socket to receive trace dump requests on. Having
  different sockets allows us to install different sets of access control rules.

- A minor refactor to allow us to share common pieces of implementation
  between the java and native dumping code. This will also allow us to
  add a unit test for all file / directory related logic.

There are two java trace specific additions here :
- We use SO_PEERCRED instead of trusting the PID written to the seocket
  because requests come in from untrusted processes.
- Java trace dumps are not interceptible.

kJavaTraceDumpsEnabled is set to false for now but the value of the flag
will be flipped in a future change.

Bug: 32064548
Test: Manual; Currently working on a unit_test for CrashType.

Change-Id: I1d62cc7a7035fd500c3e2b831704a2934d725e35
2017-05-18 12:01:14 +00:00
Josh Gao
460b336d6a tombstoned: fix a race between intercept and crash_dump.
Previously, there was no way to detect when tombstoned processed an
intercept request packet, making it possible for a intercept request
followed by a crash_dump being processed in the wrong order.

Add a response to intercept registration, to eliminate this race.

Test: debuggerd_test
Change-Id: If38c6d14081ebc86ff1ed0edd7afaeafc40a8381
2017-03-30 16:49:02 -07:00
Josh Gao
807a45807b tombstoned: refactor request dequeuing a bit.
Also make it loop, so that upon failing to start a dequeued crash
request, we continue to the next one.

Bug: http://b/36685795
Test: debuggerd_test
Change-Id: I94889125f16f4681c6fa0fa9cac456302602ce01
2017-03-30 16:19:53 -07:00
Josh Gao
13078245a0 tombstoned: don't increment num_concurrent_dumps until success.
Previously, we would increment num_concurrent_dumps and fail to
decrement it if we failed to start the request. Change this to
only increment after we've successfully started the dump.

Bug: http://b/36685795
Test: debuggerd_test
Change-Id: I66169ed56ed44271e1d8fe1298d95260be7a32a3
2017-03-30 14:51:38 -07:00
Josh Gao
55f79a5953 tombstoned: turn off signal handlers.
Don't try to connect to ourselves in a signal handler (e.g. if someone
does `killall -ABRT tombstoned`).

Test: killall -ABRT tombstoned
Change-Id: Ib69a206f741acb523c9f2883d474c940b6ebfab2
2017-03-06 12:30:25 -08:00
Josh Gao
8830c95def tombstoned: create tombstones with 0640 permissions.
Make tombstones group readable to allow them to be picked up by the
dropbox service.

Bug: http://b/35979630
Test: killall -ABRT rild; dumpsys dropbox
Change-Id: If57cc17563c80d5b5c4887b0937905bffef6b231
2017-03-06 12:30:25 -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
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
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