Commit graph

57306 commits

Author SHA1 Message Date
Elliott Hughes
e65e002102 Add a few more trivial socket_spec.h tests.
Also remove some dead code. The "missing port" case in
parse_tcp_socket_spec hasn't been meaningful since we put the default
port back.

Test: treehugger
Change-Id: I40958f0f1c2dd7f0315142c2c0363a70fe6f80fe
2020-05-12 16:38:11 -07:00
Tom Cherry
a269c7c3d1 Merge changes I9d6dde2c,I38bfcba5
* changes:
  logd: separate LogStatistics from LogBuffer
  logd: remove LogFindWorst
2020-05-12 15:55:50 +00:00
Josh Gao
a227c19ef2 Merge changes Id8d9fa6c,I47d3ad50,I7cebbf75,Id10e320a
* changes:
  adbd: avoid compiling more code in the daemon.
  adb: don't run all of the tests again over TCP in coverage.
  adbd: respect ADB_TRACE on host adbd.
  adb: mark kMaxProcessNameLength as constexpr.
2020-05-12 05:32:48 +00:00
Treehugger Robot
8987016b1e Merge changes I24e70952,I652560ad
* changes:
  adb: use transport-id to make coverage script faster.
  adb: add `adb transport-id` command.
2020-05-12 02:22:27 +00:00
Tom Cherry
bf3b47a031 Merge "logd: don't poll() before recvmsg()" 2020-05-12 00:31:37 +00:00
Treehugger Robot
1d77251d76 Merge "Remove unneeded optimize_for lite" 2020-05-11 23:49:29 +00:00
Yifan Hong
d6b307fb15 Merge "vts_processgroup_validate_test: make deps static" 2020-05-11 19:29:39 +00:00
Lorenzo Colitti
cc39283883 Merge "Simplify code that parses ifa_flags." 2020-05-11 15:34:10 +00:00
Tom Cherry
64e9016351 logd: separate LogStatistics from LogBuffer
LogStatistics is intertwined with LogBuffer, even relying on it for
thread safety.  This needs to change to have a proper
LogBufferInterface, so this CL separates them.  Specifically:

1) Adding a lock to LogStatistics and adding thread annotations to
   ensure that data structures are protected appropriately.
2) Moving prune_rows calculation into LogStatistics so it is done
   while holding this lock.
3) Using LogStatistics instead of LogBuffer where appropriate.

Note that there should not be a significant performance regression
with this lock, as it will almost always been uncontended.  If
anything, it should alleviate pressure from LogBuffer's lock.

Test: logging unit tests
Change-Id: I9d6dde2c96c9f024fa0341711c7bc63379e8e406
2020-05-11 07:55:52 -07:00
Tom Cherry
b6b78e9bb4 logd: remove LogFindWorst
LogStatistics relies on LogBuffer's lock for thread safety, but that
will be cleaned up in future CLs.  It won't be possible to return a
'LogFindWorst' object that references internal LogStatistics pointers
in a thread safe way, so we remove this and provide a more simple
interface.

This also removes unnecessary allocations; std::array of 2 or 32
entries is small enough to allocate on the stack.

Test: logging unit tests
Change-Id: I38bfcba5b08c640ffd3af5c078bc716688f6edf8
2020-05-11 07:54:34 -07:00
Lorenzo Colitti
077d1ea61b Simplify code that parses ifa_flags.
When parsing an RTM_NEWADDR or RTM_DELADDR, ifaddr is always
present (unless the message is invalid). So ifaddr->ifa_flags is
always known before any attributes are parsed.

Bug: 155005831
Test: atest NetworkStackNextIntegrationTests:IpClientIntegrationTest continues to apss
Change-Id: Id1998faccca7d81c1b7f3e85e4912aa22919e94a
2020-05-11 22:33:27 +09:00
Treehugger Robot
6153b71aea Merge changes I57cb2003,I569d2b81,I01a10e36
* changes:
  libnetutils/packet.c - create socket with close-on-exec
  libnetutils/packet.c - fix a raw socket reception race
  libnetutils/packet.c - fix a socket leak on bind error
2020-05-10 17:29:35 +00:00
Lorenzo Colitti
b7dd29354f Merge "Parse IFA_F_* values above 0x80." 2020-05-10 05:29:59 +00:00
Lorenzo Colitti
096fc5351f Parse IFA_F_* values above 0x80.
In RTM_NEWADDR messages, the first 8 flags are reported in the
ifa_flags field in struct ifaddrmsg, but flags above 0x80 are
reported in the IFA_FLAGS attribute. NetlinkEvent currently only
looks at ifa_flags, so it cannot see higher-value flags such as
IFA_F_STABLE_PRIVACY. Fix this by parsing the IFA_FLAGS
attribute.

Bug: 155005831
Test: makes new test in aosp/1295495 pass
Change-Id: I723f1106cbcea2186fc6452305942a0f8301fd2a
2020-05-10 11:36:59 +09:00
Maciej Żenczykowski
39c26d63cd libnetutils/packet.c - create socket with close-on-exec
This prevents fork/exec leaking sockets to child processes.

Test: builds, atest
Bug: 155297277
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I57cb2003dd75b0bc5528978fd131730273e37a43
2020-05-08 22:34:37 -07:00
Maciej Żenczykowski
0129aaae86 libnetutils/packet.c - fix a raw socket reception race
A socket created bound to a specific protocol can receive packets before
it's bound to a specific interface/mac.

It's best to rely on the bind().

This replicates the way packet sockets are created in external/android-clat.
See: ring.c ring_create() and clatd.c configure_packet_socket()

Test: builds, atest
Bug: 155297277
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I569d2b81a396f352ab5d1b71bd5ad0d96217aab1
2020-05-08 22:34:37 -07:00
Maciej Żenczykowski
b7f370c014 libnetutils/packet.c - fix a socket leak on bind error
and clean up the code a little bit while at it.

Test: builds, atest
Bug: 155297277
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I01a10e36f852cde1b93a91f95b51294a434885ab
2020-05-08 22:34:37 -07:00
Christopher Ferris
5445c73012 Merge "Fix mac build." 2020-05-09 04:49:07 +00:00
Woody Lin
c5f0640e48 Merge "InitFatalReboot: Trigger panic explicitly for init_fatal_panic" 2020-05-09 01:51:04 +00:00
Christopher Ferris
8a6dff22dc Fix mac build.
Add an inline for mmap64 to use on mac.

Bug: 156053599

Test: Builds.
Change-Id: Id02e2c2f40acea2bdef604e9b80b70a85a941927
2020-05-08 15:30:21 -07:00
Peter Collingbourne
5d97966e8f Merge "Add stack trace coverage to MTE tests." 2020-05-08 19:37:07 +00:00
Woody Lin
be1cf9006a InitFatalReboot: Trigger panic explicitly for init_fatal_panic
The exit of init panics the system *after* process context (mm, stack,
...etc.) are recycled, according to Linux kernel's 'do_exit'
implementation. To preserve most init process context for debugging,
triggers the panic via proc-sysrq explicitly.

Note: after this change, there will be no "Attempt to kill init" panic
when androidboot.init_fatal_panic is set.

Test: Insert data abort fault in init, the full process context is
      preserved in memory dump captured after panic.
Bug: 155940351
Change-Id: I3393bd00f99b8cb432cfa19a105b7d636b411764
2020-05-09 01:30:32 +08:00
Peter Collingbourne
bbe6905d7e Add stack trace coverage to MTE tests.
It's impractical to test the contents of the stack trace, but we
should at least test that *a* stack trace is present, which would
have caught the bug fixed by r.android.com/1306754 .

Bug: 135772972
Change-Id: Ic5e0b997caa53c7eeec4e5185df5c043c9d4fe3d
2020-05-08 10:14:47 -07:00
Jiyong Park
d427b54c53 Merge "Revert "Make libstatssocket a shared_lib"" 2020-05-08 08:11:24 +00:00
Jiyong Park
3e0ec0f7f7 Revert "Make libstatssocket a shared_lib"
This reverts commit 29512fbf70.

Reason for revert: breakage https://android-build.googleplex.com/builds/quarterdeck?branch=aosp-master&target=run_bluetooth_host_native_tests&lkgb=6474123&lkbb=6474183&fkbb=6474137

Bug: 156046846
Test: m on full-eng

Merged-In: I5889dd718536f5f2c693b4c2e7331c9cc2eb2ac9
Change-Id: If28b7590d4e58e44a24581f3b5891b2441504801
2020-05-08 07:57:09 +00:00
Jiyong Park
d25f5dbba9 Merge "Make libstatssocket a shared_lib" 2020-05-08 02:12:58 +00:00
Yifan Hong
2572f23af8 vts_processgroup_validate_test: make deps static
Test: pass
Fixes: 155959743
Change-Id: I730526955a40ae00a97f487e423a00c743f75d53
2020-05-07 12:41:45 -07:00
Christopher Ferris
7821048120 Merge "Change call to mmap64." 2020-05-07 18:35:54 +00:00
Peter Collingbourne
4cd4b45a32 Merge "Add support for MTE error reports in tombstones." 2020-05-07 17:51:51 +00:00
Tom Cherry
972f1ba172 Merge changes Ib0f33d2f,Ife6c09dd,I55ed5656
* changes:
  logd: enable -Wextra
  logd: don't check of the timestamp of audit messages is monotonic
  Remove the monotonic option for logging
2020-05-07 16:12:33 +00:00
Christopher Ferris
7b9f35c9de Change call to mmap64.
The code was using an off64_t but calling mmap. This caused the code
to abort on 32 bit.

Add a unit test that would abort on the previous version.

Bug: 155662887

Test: New unit test passes.
Change-Id: I7a6efbc0d4227403c3d08a08deea56f239382157
2020-05-06 22:32:18 +00:00
Yifan Hong
1af4a81f7d Merge "libsnapshot: fix incorrect assumption of cow images" 2020-05-06 22:06:12 +00:00
Joshua Duong
2814928567 Merge "[adb client] Fix mdns discovery service registry." 2020-05-06 21:39:59 +00:00
Tom Cherry
053dacab48 logd: enable -Wextra
Also drop -Wall and -Werror since they're included by default now.

Test: build
Change-Id: Ib0f33d2f02e00aaf544cb0ce5acec5d8acaa8a81
2020-05-06 13:57:57 -07:00
Tom Cherry
c64dd8e727 logd: don't poll() before recvmsg()
LogListener uses the libsysutils SocketListener class to read incoming
log messages, which means that it poll()'s to wait for new data then
calls recvmsg() when this data is available.  That is unnecessary,
since this is a blocking socket, it already has a dedicated thread,
and we're not using any other SocketListner features, so a tight loop
of recvmsg() is sufficient.

Below are the stats from simpleperf during a framework restart.  To
get an apples to apples comparison, these stats calculate the overhead
of receiving the message as 1 - (<number of perf events dispatching
the logs in logd>/<total number of perf events for the listener thread>).

With SocketListener / poll()
378563153 total events for the listener thread - SocketListener::runListener()
245799364 events for reading and dispatching logs + recvmsg() - LogListener::onDataAvailable()
67622952 events for recvmsg() inside LogListener::onDataAvailable()
=> (378563153 - 245799364) = 132763789 SocketListener + poll() overhead
=> (132763789 + 67622952) = 200386741 total overhead to for recvmsg() + poll() + SocketListener
=> (200386741 / 378563153) = 52.9% overhead to read each log message.

Without SocketListener / poll()
324802401 total events for the new listener thread - LogListener::ThreadFunction()
133208105 events for recvmsg()
=> (133208105 / 324802401) = 41% overhead to read each log message.

This shows a 22.5% = (41 - 52.9)/52.9 reduction in cost spent for each log message.

Test: logging unit tests
Test: simpleperf
Change-Id: I1f93b7a06fac6adce8e64e727bf6d8c5935c77c9
2020-05-06 13:44:10 -07:00
Tom Cherry
517808981e logd: don't check of the timestamp of audit messages is monotonic
This is the last isMonotonic() user and can go away.  This timestamp
is set in the kernel source in either the audit_get_stamp() or
__audit_syscall_entry() functions.  In both cases, the value used is
from ktime_get_coarse_real_ts64(), which is a realtime timestamp.

Test: audit messages show in the log correctly.
Change-Id: Ife6c09dd97fccdfc7a8f07ee63161079ae2eccc4
2020-05-06 13:37:33 -07:00
Tom Cherry
f2c2746aba Remove the monotonic option for logging
This has been around for ~5 years but there has been roughly no
adoption, so remove this as we clean up the logging code.

Future efforts may track the monotonic timestamp in all cases.

Test: logging unit tests
Change-Id: I55ed565669f923988e741f6b384141bba893630d
2020-05-06 13:37:33 -07:00
Tom Cherry
72fdec1777 Merge changes I9a357a3e,I7cfc6393,I69148243
* changes:
  logd: start cleaning up LogReaderThread
  logd: use std::function and lambdas where appropriate
  logd: rename LogTimes -> LogReaderThread
2020-05-06 20:34:42 +00:00
Treehugger Robot
c3d30bfdff Merge "Fix GetGlobalVariableOffset with tagged pointer in aarch64" 2020-05-06 05:53:45 +00:00
David Anderson
6bc06af640 Merge "libfiemap: Remove brittle tests." 2020-05-06 02:14:05 +00:00
David Anderson
f74f58fa17 Merge "liblp: Add integer overflow checks when aligning." 2020-05-06 01:36:10 +00:00
Yifan Hong
e6c1a84276 libsnapshot: fix incorrect assumption of cow images
libsnapshot used to assume CoW images are always mapped
with device mapper, and call GetDeviceString directly.
However, in tests, it is possible that it is mapped as loop
devices. Fix the incorrect assumption and calls
IImageManager::GetMappedImageDevice instead.

Test: libsnapshot_fuzzer with corpus
Bug: 154633114
Change-Id: I1ec39744480e514ae7a7902643ed863e0ca0a340
2020-05-05 18:01:15 -07:00
David Anderson
e3fa729dc2 libfiemap: Remove brittle tests.
libfiemap functionality is extensively tested via libsnapshot, gsid, and
fiemap_writer_test. However those tests rely on the configuration of the
device, and libfiemap has fairly different behavior based on whether FBE
or metadata encryption is in use. (The former will use loop devices, the
latter uses dm-linear).

To expand coverage, we added tests with very complicated nesting,
creating fiemaps on a rw partition mounted off a device backed by a
fiemap. Unsurprisingly, this was brittle to begin with, and now
consistently fails due to the intermediate partition not having
sepolicy.

Given the preference toward metadata encryption, and the fact that the
FBE mode will still be properly tested via VTS, let's just remove these
tests.

Bug: 148874852
Test: fiemap_image_test
Change-Id: I7be7d44dea81508505c050ed995b3b78086ad35f
2020-05-05 15:33:21 -07:00
Josh Gao
a11d27f920 adb: use transport-id to make coverage script faster.
Test: ./coverage/gen_coverage.sh
Change-Id: I24e70952946ad91d51acf9bda386826e4e73a0d2
2020-05-05 14:44:01 -07:00
Josh Gao
3441f232ab adb: add adb transport-id command.
Make it possible to safely script waiting for a device to go away after
root/unroot.

Test: manual
Change-Id: I652560ad1d88a5c6a1e8ea5787c3cf165c82aa63
2020-05-05 14:43:53 -07:00
David Anderson
42c2733d6c liblp: Add integer overflow checks when aligning.
This will prevent ubsan crashes on invalid inputs.

Bug: 155510366
Test: liblp_test gtest
Change-Id: Id6dd8badd0025d6cac3113c3f9076ea3f4d9c175
2020-05-05 11:37:53 -07:00
Yifan Hong
2e66043394 Merge "Add tests for zero snapshot size." 2020-05-05 15:23:35 +00:00
Joshua Duong
077ac11106 [adb client] Fix mdns discovery service registry.
We were getting stale service ip addresses because we weren't
destroying the sdref correctly.

Also, we were leaking the ResolvedServices when removing it from the
ServiceRegistry. Converted them to smart pointers to fix that.

Bug: 153343580

Test: test_adb.py
Change-Id: Ib7c1dbf54937d4ac6d9885cb5f7289bef616d12e
2020-05-05 00:21:12 -07:00
Tom Cherry
cef47bb38c logd: start cleaning up LogReaderThread
1) We can use real member functions with std::thread and
   std::function, so use those instead of the 'me' pointer.
2) Don't expose member variables directly.
3) Rename and document member variables, since all of their references
   are being touched anyway.

Test: logging unit tests
Change-Id: I9a357a3ea8691433d58687c95356b984b83e9c36
2020-05-04 17:44:52 -07:00
Tom Cherry
320f5968da logd: use std::function and lambdas where appropriate
Test: logging unit tests
Change-Id: I7cfc63937b5dadb5547c4661ca2f5204d7b4a174
2020-05-04 17:37:14 -07:00