Commit graph

71 commits

Author SHA1 Message Date
Bernie Innocenti
b664724525 bionic: Convert res_send.c to poll()
Bug: 5854418
Test: adb shell /data/nativetest64/bionic-unit-tests-static/bionic-unit-tests-static
Test: manually:
    - flash and boot device
    - connect to wifi
    - launch WebView and resolv a few domains
Change-Id: I7b488e6d061d99a8a3c4bba69c2ac8609257eb6a
2018-07-05 11:39:09 +09:00
Lorenzo Colitti
5f02720c88 fchown DNS lookup sockets to AID_DNS.
Currently DNS lookups are all sent as UID 0. In N we added an
AID_DNS user, but we never used it. A separate UID allows us to
account for and route DNS traffic differently from other UID 0
traffic such as kernel-originated traffic.

Bug: 70673901
Test: DNS lookups continue to work
Test: netd_{unit,integration}_test pass
Change-Id: Ife3ca7df45de51b92437d2cfe627fb4703b672fb
2018-05-09 01:04:05 +09:00
Ben Schwartz
27dd915147 Pad queries when EDNS0 is enabled.
Behavior is compliant with
https://tools.ietf.org/html/draft-ietf-dprive-padding-policy-04

EDNS0 is only enabled when the netcontext requests it, i.e. in DNS-over-TLS
mode.

Bug: 69623036
Bug: 64133961
Test: Wireshark verified. Integration tests echo padding and pass.
Change-Id: I5ef600e02a572d281441e890cc981614f150629b
2018-04-02 05:28:16 +00:00
Ben Schwartz
e7190ce3f2 Enable EDNS and the DO-bit if the netcontext asks
This effectively enables these features only in TLS mode
Test: Integration tests pass
Bug:69623036

Change-Id: I153a259b0c07717f664ee268b43da867a9b42152
2018-03-21 01:01:29 +00:00
Ben Schwartz
6eed8e1bb6 Lay the groundwork for enabling EDNS0 in queries.
This change does not enable EDNS0, so it should not
result in any behavior change.  However, enabling EDNS0
should now be possible with only a small additional change
to "flip the switch".

This change has also landed in NetBSD upstream
(http://gnats.netbsd.org/52578) so this change reduces
divergence from upstream.

Most of the code in this change is for caching of queries that contain
an additional section.

Bug: 15132200
Test: Added integration tests for fallback to the netd suite.
Change-Id: Ic64bed0754e1d529dc0c0ab6a5e2f1ea201ff0d5
2018-02-05 14:41:01 -05:00
Ben Schwartz
90a83beb4d Make use of the DNS query hook in the netcontext
This will allow netd to run queries over TLS:
https://android-review.googlesource.com/#/c/391513/
https://android-review.googlesource.com/#/c/380593/

Bug: 34953048
Test: Device tests pass.  No issues during manual testing.
Change-Id: I8d613322307fc40cdba59b82599eda753697278f
2017-05-22 18:37:25 -04:00
Treehugger Robot
761bb2be4d Merge "Add the DNS query hook to net context" 2017-05-22 02:51:36 +00:00
Ben Schwartz
f0305dcee9 Add the DNS query hook to net context
This change
 - adds a query hook to android_net_context
 - exposes relevant definitions to netd
 - corrects a bug in query hooks' interaction with the cache

This change does not introduce any code to read the query hook
from the net context or make use of it.

Bug: 34953048
Test: Netd test suite passes
Change-Id: Ie091980e22ce9da07a3c4d387b371e544379d762
2017-05-18 12:03:11 -04:00
Christopher Ferris
7a3681e5b6 Move libc_log code into libasync_safe.
This library is used by a number of different libraries in the system.
Make it easy for platform libraries to use this library and create
an actual exported include file.

Change the names of the functions to reflect the new name of the library.

Run clang_format on the async_safe_log.cpp file since the formatting is
all over the place.

Bug: 31919199

Test: Compiled for angler/bullhead, and booted.
Test: Ran bionic unit tests.
Test: Ran the malloc debug tests.
Change-Id: I8071bf690c17b0ea3bc8dc5749cdd5b6ad58478a
2017-05-03 08:50:43 -07:00
Nick Kralevich
62c03a4ff4 Cleanup ANDROID_DNS_MODE and BIONIC_DNSCACHE
For security reasons, when a binary is executed which causes a security
transition (eg, a setuid binary, setgid binary, filesystem capabilities,
or SELinux domain transition), the AT_SECURE flag is set. This causes
certain blacklisted environment variables to be stripped before the
process is executed. The list of blacklisted environment variables is
stored in UNSAFE_VARIABLE_NAMES. Generally speaking, most environment
variables used internally by libc show up in this list.

Add ANDROID_DNS_MODE to the list of unsafe variables.
Similar to RESOLV_HOST_CONF and RES_OPTIONS (which are already
blacklisted), this variable controls how name resolution requests are
handled. Allowing ANDROID_DNS_MODE to be set across a security
boundary could induce resolution failures or otherwise impact
name resolution.

Remove BIONIC_DNSCACHE. This does not appear to be used, and setting
this variable across a security boundary could cause name resolution
problems.

Test: Android compiles and runs with no obvious problems.
Change-Id: I835a7b42d6afbc9c67866594c7951cfd9b355d81
2017-04-03 08:44:38 -07:00
Erik Kline
40d51f0d28 Remove all system properties references
Test: as follows
    - build
    - flash
    - runtest -x system/netd/tests/netd_integration_test.cpp
Bug: 33308258
Change-Id: I59526cb91e91b35a63ba6b413d444712568463e4
2016-12-05 12:45:10 +09:00
Treehugger Robot
f8b4ff4aa1 Merge "Remove obsolete #include and comment." 2016-12-05 00:01:34 +00:00
Elliott Hughes
6eb8fb5f86 Remove obsolete #include and comment.
Bug: http://b/33308258
Test: builds
Change-Id: Id6bbdae536a12134899fa57ea799f488d018db00
2016-12-02 17:51:56 -08:00
Erik Kline
0e4cdff76b Don't flush the per-netid cache when adding nameservers.
This wasn't really necessary in the >= Lollipop architecture.

Test: netd_integration_test fails (fixing separately)
Bug: 32517984
Change-Id: I8115bfe913ae6609f64b55161a1c8e28ce2619cf
2016-12-02 04:28:43 +09:00
Elliott Hughes
dfb74c5f59 Minor copyright header unification.
Regenerating the NOTICE file the other day left me scratching my head at
various "how do they differ?" cases, resolved by this patch.

Test: N/A
Change-Id: I4230bfa1d7ec842a4b9fb8c73dd3b39443d74054
2016-10-24 12:57:55 -07:00
Elliott Hughes
a9209d7a0e Fix some easy cases of __ANDROID__ versus __BIONIC__.
We need to make a clearer distinction for bionic on the host. This patch
doesn't fully address things like "should host bionic try to talk to netd?"
for now, but is a step in the right direction.

Bug: http://b/31559095
Test: bionic tests.
Change-Id: I49812f8b75d9d78c4fd8a8ddf5df1201d63771d6
2016-09-16 18:27:07 -07:00
Pierre Imai
06e2202a4c Always update search domain paths.
_resolv_set_nameservers_for_net() so far did not update the search
paths, unless the servers changed as well.

BUG: 28437641
Change-Id: Id31f2d97c173e00357fb2ba95908afb4572c0fc1
2016-05-11 11:06:55 +09:00
Pierre Imai
8b8611a0e6 Record the resolution start time on errors.
Also only record samples on the first try for a server.

BUG: 25731675

Change-Id: I10a68813c6636874e63aca1db661e63e1af72a2d
2016-05-02 17:39:19 +09:00
Pierre Imai
1b069a990a Fix DNS search path info.
Fix the resolver information returned by
android_net_res_stats_get_info_for_net,
erroneously included MAXDNSRCH empty results if no search path was set.

BUG: 25731675
Change-Id: I97ef5d2d47dc62ca403a3323c7f14902e47b29b6
2016-04-27 12:24:32 +09:00
Pierre Imai
97c9d73a87 Add new info functions to resolver for use by Netd.
android_net_res_stats_get_info_for_net returns the current name servers, search
domains, parameters and stats for the given network ID.

android_net_res_stats_aggregate provides statistics such as errors counts from
the raw stats data reported by android_net_res_stats_get_info_for_net.

android_net_res_stats_get_usable_servers uses the data returned by
android_net_res_stats_aggregate to determine which of the servers are
considered valid or broken by the resolver.

BUG: 25731675

Change-Id: I6059b68e5e8b809027a4d3135f6081588bee8a7d
2016-04-21 10:07:26 +09:00
Pierre Imai
fff356786f Store DNS server count in resolv_cache.
Instead of keeping a sentinel after nameservers[], nsaddrinfo[] and
nstats[], store the server count in the structure, freeing up memory and
eliminating the need to enumerate the server count every time
_resolv_is_nameservers_equal_locked() is invoked.

Also increase MAXNS from 3 to 4.

BUG: 28153323
Change-Id: I11a7257af695157c9e32019cd00c67b535b63c75
2016-04-21 10:07:24 +09:00
Pierre Imai
360800d829 Reduce the amount of logging in Bionic's resolver.
Change-Id: I250d9a352f1fa0cafef349d0e23f72a9dd8e399d
2016-04-06 11:25:30 +09:00
Pierre Imai
03844d8cdb Fix off-by-one error in res_cache.c
Change-Id: I58264902c123b3bc0d392d17837aa537ca0a3ca2
2016-04-05 16:19:57 +09:00
Pierre Imai
6b3f0d65f2 Ignore unreliable DNS servers.
Collect statistics about DNS query success state and delay. Ignore
servers that have been tried at least five times and have a success rate
of < 0.25. Retry these servers once every 180s.

Bug: 25731675
Change-Id: I78e24f43e388dca82fb81835e1796f4c7dce8da3
2016-04-05 11:42:43 +09:00
Pierre Imai
0967fc7e59 Copy the entire zero-separated DNS seach domain string.
The DNS search string contains zeros as domain separator. The resolver
code erroneously used strlcpy(), which resulted in only the first domain
to be copied. The code uses pointers into this string to access the
individual domains. Since the structure is zero-initialized, this bug only
resulted in zero-length domains instead of accessing unitialized memory.

BUG: 27312811
Change-Id: Ia9d066c405dfcc5e82d6766d93ead2ce574e7b0d
2016-02-29 16:50:38 +09:00
Elliott Hughes
b83d6747fa Improve FORTIFY failure diagnostics.
Our FORTIFY _chk functions' implementations were very repetitive and verbose
but not very helpful. We'd also screwed up and put the SSIZE_MAX checks where
they would never fire unless you actually had a buffer as large as half your
address space, which probably doesn't happen very often.

Factor out the duplication and take the opportunity to actually show details
like how big the overrun buffer was, or by how much it was overrun.

Also remove the obsolete FORTIFY event logging.

Also remove the unused __libc_fatal_no_abort.

This change doesn't improve the diagnostics from the optimized assembler
implementations.

Change-Id: I176a90701395404d50975b547a00bd2c654e1252
2016-02-26 22:06:17 -08:00
Elliott Hughes
6170693e28 Make ThreadLocalBuffer a class rather than a macro.
Bug: 19995392
Change-Id: I497c512648fbe66257da3fb3bcd5c9911f983705
2015-03-31 10:56:58 -07:00
Yabin Cui
9ecb7f40d0 am c3307dc4: Merge "Better control of pthread keys used in bionic."
* commit 'c3307dc43b2526c4031837738b139d22831c5d09':
  Better control of pthread keys used in bionic.
2015-03-05 18:33:31 +00:00
Yabin Cui
4a2891d8c8 Better control of pthread keys used in bionic.
Change-Id: I1e1bc77c0e7879baead6c3417282ce549a1153b5
2015-03-04 16:53:23 -08:00
Elliott Hughes
0772f933a4 am 6cf2cf8b: am 542b94d9: Merge "Remove unused CONFIG_SECONDS."
* commit '6cf2cf8bf26b99b7318791c75cbccfd95893b04e':
  Remove unused CONFIG_SECONDS.
2015-01-30 21:16:34 +00:00
Elliott Hughes
4dcfccff8d Remove unused CONFIG_SECONDS.
Bug: https://code.google.com/p/android/issues/detail?id=65951
Change-Id: I8ae7057c68e16618de6dd06cf052426c6cad8a3d
2015-01-29 21:47:37 -08:00
Elliott Hughes
5bf4a1729a am dedacf10: am 5c7964c5: Merge "Clean up <stdlib.h> slightly."
* commit 'dedacf109b35e74d76594c29560a09f4ef3eb94d':
  Clean up <stdlib.h> slightly.
2015-01-27 05:00:11 +00:00
Elliott Hughes
5c7964c5f1 Merge "Clean up <stdlib.h> slightly." 2015-01-27 04:49:07 +00:00
Lorenzo Colitti
ecbeee61ed am 329db346: am f2d02c38: Merge "Make bionic compile even if resolver debugging is enabled."
* commit '329db346f54c629e0c9fcc98c21c19619a573e9b':
  Make bionic compile even if resolver debugging is enabled.
2015-01-27 04:14:09 +00:00
Elliott Hughes
76f8916b90 Clean up <stdlib.h> slightly.
Interestingly, this mostly involves cleaning up our implementation of
various <string.h> functions.

Change-Id: Ifaef49b5cb997134f7bc0cc31bdac844bdb9e089
2015-01-26 14:28:41 -08:00
Lorenzo Colitti
616344d169 Make bionic compile even if resolver debugging is enabled.
The code now compiles with all combinations of DEBUG and
DEBUG_DATA except DEBUG_DATA=1, DEBUG=0, which is unsupported.

Change-Id: I9035a65c649df73092f1fc0864ae1cdd9a14aa3b
2015-01-26 16:05:27 +09:00
Elliott Hughes
6428c625e8 am 7d196768: am 927d8be7: Merge "Fix build error when XLOG is enabled"
* commit '7d196768029f36b0e3fa57ba747ce58ef2b1c9d6':
  Fix build error when XLOG is enabled
2015-01-21 02:21:57 +00:00
Patrick Tjin
a6a0949b1d Fix build error when XLOG is enabled
(cherrypick of 79a49c9857f3949fc13373eeb179f27b6ecdca81.)

Change-Id: I7bb44fd1fe3ef2ddfc115247f328eccfceeb5352
Signed-off-by: Patrick Tjin <pattjin@google.com>
2015-01-20 16:12:45 -08:00
Yabin Cui
bb3579f878 am 96cd50f2: am 0e32e39d: Merge "Fix pthread key num calculation."
* commit '96cd50f2fc33b0d342f1733894b06fd59a725519':
  Fix pthread key num calculation.
2014-12-13 03:03:51 +00:00
Yabin Cui
6c238f2926 Fix pthread key num calculation.
Bug: 18723085
Change-Id: Iba2c834b350e4cdba0b2d771b221560a3e5df952
2014-12-12 17:00:08 -08:00
Lorenzo Colitti
8a94b864bf am e5477f83: Fail queries fast if no DNS servers are configured.
* commit 'e5477f83b0a639b86d8cbe710f25d9808a8f72af':
  Fail queries fast if no DNS servers are configured.
2014-12-02 07:00:47 +00:00
Lorenzo Colitti
e5477f83b0 Fail queries fast if no DNS servers are configured.
When no DNS servers are configured (and thus there is no chance
that the DNS query will suceed), res_nsend returns early, but
it does not tell the cache that the query has failed.
Therefore, if the caller retries the query, it will block for
PENDING_REQUEST_TIMEOUT (= 20 seconds) waiting for the "existing
query" (which isn't actually doing anything) to complete.

Bug: 18240188
Bug: 18327075
Change-Id: I0df13ff4a17ee65e640be96695a3af31b020963a
2014-12-01 20:03:25 +00:00
Dan Albert
a2220ffb74 am 72d72d91: Merge "Replace uses of sprintf(3) with snprintf(3)."
* commit '72d72d91262fabe6bc169618ef3acb0721441cf0':
  Replace uses of sprintf(3) with snprintf(3).
2014-10-09 00:13:06 +00:00
Dan Albert
8b3b4fa0ae am 72d72d91: Merge "Replace uses of sprintf(3) with snprintf(3)."
* commit '72d72d91262fabe6bc169618ef3acb0721441cf0':
  Replace uses of sprintf(3) with snprintf(3).
2014-10-09 00:12:30 +00:00
Dan Albert
cfd8c45725 Replace uses of sprintf(3) with snprintf(3).
At -00, the compiler warns about sprintf(3), and it is promoted to an
error by -Werror.

Change-Id: Ibb380d27d7eb09dda8ac785be2478d656b379190
2014-10-08 16:12:27 -07:00
Elliott Hughes
d87d401ab1 Improve <sys/cdefs.h>.
Fix and use __RENAME (and lose ___RENAME --- two underscores should be
enough for anybody). This was the point of this change, because I want
to use __RENAME to support the two basename variants and the two
strerror_r variants.

Lose a bunch of macros that weren't being used.

Lose three dead files from the DNS code.

Bug: 17784968

(cherry picked from commit 2cfb4e8e2e)

Change-Id: I5e96146f92c0521248c78c0933bec5e9a9818222
2014-10-07 11:40:09 -07:00
Lorenzo Colitti
33a73bfa07 When comparing DNS server configs, also compare number of servers
Bug: 16070602
Change-Id: I605f1cca50b08479ebcad290b3bd179f59be8a96
2014-09-11 08:36:12 +09:00
Lorenzo Colitti
da0ed4cbfa am c71483c0: Merge "When comparing DNS server configs, also compare number of servers"
* commit 'c71483c0b38a6b4f2675f0bffa221dcf175c34ac':
  When comparing DNS server configs, also compare number of servers
2014-09-09 10:42:23 +00:00
Lorenzo Colitti
c71483c0b3 Merge "When comparing DNS server configs, also compare number of servers" 2014-09-09 10:22:18 +00:00
Lorenzo Colitti
bce18c9163 When comparing DNS server configs, also compare number of servers
Bug: 16070602
Change-Id: I605f1cca50b08479ebcad290b3bd179f59be8a96
2014-09-09 19:20:26 +09:00