summaryrefslogtreecommitdiff
path: root/server/FirewallController.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Delete FirewallController::replaceUidChain.Lorenzo Colitti2022-01-141-5/+0
| | | | | | | | | This method has no callers. It does nothing except call TrafficController::replaceUidOwnerMap, but TrafficController functionality is moving out of netd. Test: m Change-Id: I9942a5a6fcf0c137cd1cdc6019c835dac0f1d765
* [NETD-TC#6] Clean up the dependency between FirewallController andwaynema2021-12-021-32/+0
| | | | | | | | TrafficController. Test: m; flash; boot Test: atest FirewallControllerTest TrafficControllerTest Change-Id: I0a8f3f2e9c1f4510021570e7894a56e4998f3ede
* [NETD-TC#5] Clean up the relevant non-bpf codes forwaynema2021-12-021-210/+5
| | | | | | | | | | FirewallControllerTest. Delete TestReplaceAllowlistUidRule, TestReplaceDenylistUidRule and TestDiscoverMaximumValidUid from test cases because they call the function makeUidRules() which run non-bpf codes. Change-Id: I7e423efc5e3a9885a15e1616a9b6e738ead1c146
* Never send packets with a source of ::1 on the wire.Maciej Żenczykowski2021-10-151-11/+15
| | | | | | | | | | | | | | | Doing so is obviously invalid, and certain carriers will tear down the connection if such packets are sent on their network. This is done by adding an ip6tables rule to fw_OUTPUT that drops all packets with a non-lo egress interface and a source of ::1. Test: boot device, "adb root && adb shell ip6tables-save | egrep fw_OUTPUT" Bug: 190368103 Bug: 198896920 Bug: 203096965 Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: Ifb272d48705ba756ccd7bac806e4dc2dd7488cd5
* eliminate TrafficController's mBpfEnabled & friendsMaciej Żenczykowski2021-01-201-5/+2
| | | | | | | Test: builds, atest, TreeHugger Bug: 167500195 Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I9145cd24c8be86d4a57a43c812ccd27b5fc14c67
* Add Restricted Mode Firewall ChainPatrick Rohr2020-12-021-4/+14
| | | | | | | | | Adding a new allowlist firewall chain to support restricted networking mode. See go/restricted-networking-mode. Bug: b/157505406 Test: atest netd_integration_test && atest netd_unit_test Change-Id: I0028e6fa47460e5516d759c5807a459a4700a83e
* Mostly remove "blacklist" and "whitelist" from netd.Lorenzo Colitti2020-07-301-32/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rename these to allowlist and denylist. This change is mostly automatically generated with: sed -i 's/WHITE/ALLOW/g' server/*.{cpp,h} libnetdbpf/{*.cpp,/include/netdbpf/*.h} bpf_progs/*.[ch] sed -i 's/white/allow/g' server/*.{cpp,h} libnetdbpf/{*.cpp,/include/netdbpf/*.h} bpf_progs/*.[ch] sed -i 's/BLACK/DENY/g' server/*.{cpp,h} libnetdbpf/{*.cpp,/include/netdbpf/*.h} bpf_progs/*.[ch] sed -i 's/black/deny/g' server/*.{cpp,h} libnetdbpf/{*.cpp,/include/netdbpf/*.h} bpf_progs/*.[ch] sed -i 's/White/Allow/g' server/*.{cpp,h} libnetdbpf/{*.cpp,/include/netdbpf/*.h} bpf_progs/*.[ch] sed -i 's/Black/Deny/g' server/*.{cpp,h} libnetdbpf/{*.cpp,/include/netdbpf/*.h} bpf_progs/*.[ch] plus manual changes to FirewallController.h and NdcDispatcher.cpp to make them continue to use INetd::FIREWALL_WHITELIST and INetd::FIREWALL_BLACKLIST. INetd (and FIREWALL_WHITELIST and FIREWALL_BLACKLIST) are not being fixed in this change because doing so would require changing frozen AIDL files, which is a more complex undertaking. Also manually change occurrences in the test. Finally, fix some formatting errors found by clang-format, and some errors such as "a allowlist" (should be "an allowlist") or` "allowspace" (should be "whitespace"). Bug: 161896447 Test: atest netd_unit_test netd_integration_test Test: crosshatch builds, boots, no IptablesRestoreController errors in logs Change-Id: I3f5b864686651134a50e90b28fc9914bfa3f9a8e
* simplify: BpfLevel -> BpfEnabled where appropriateMaciej Żenczykowski2020-02-121-2/+1
| | | | | | | | | bpf::BpfLevel getBpfLevel() --> bool getBpfEnabled() bpf::BpfLevel mBpfLevel --> bool mBpfEnabled Test: build, atest Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: Idb5f9ed10e123a5653047b9d31c7245b9cb8a46e
* FirewallController - make mUseBpfOwnerMatch a boolMaciej Żenczykowski2020-02-111-10/+10
| | | | | | Test: builds, atest Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I422a74e7a6f44259bb5f0c7a88222328e432c35b
* Get bpf level when check bpf supportChenbo Feng2019-02-151-7/+8
| | | | | | | | | | | | Instead of return boolean, bpf support check now returns a integer represent the current bpf level on device. This level is used to decide if the device support some advanced bpf feature such as map_in_map and bpf cgroup socket filter. Delete the binder call for bpf status check since no one is using it. Bug: 111441138 Test: libnetdbpf_test, netd_integration_test Change-Id: Ib70c07647ffe491d493b4582b4b4b0eba7caf3a9
* Firewall-related commands portingLuke Huang2018-10-241-10/+16
| | | | | | | Test: built, flashed, booted system/netd/tests/runtests.sh passes Change-Id: I0fcf6ac4e5d96cbf63d6752bee7202cdef940e82
* Merge all uid owner match map into oneChenbo Feng2018-08-061-3/+0
| | | | | | | | | | | | | | | The bpf maps used for storing the uid owner match information are using the same key value pairs and the duplication can be reduced by using one single value to store all the match information for a given uid and use a configuration map to store the chain that is currently enabled. This migration can save some kernel memory space and simplify the owner match process. Bug: 79781072 Test: netd_unit_test, com.android.cts.net.HostsideRestrictBackgroundNetworkTests Change-Id: I9658321e9d4a87eaa724231d33a474113dd75019
* FirewallController: discover max uid in the current user namespaceHugo Benichi2018-07-231-8/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch gives the capability to FirewallController to discover the maximum valid uid in the user namespace in which netd is currently running, and uses that value in the whitelist uid rules. This is done by parsing the content of /proc/self/uid_map as explained in the man page of 'user_namespaces'. On the default root namespace the maximum uid is expected to be UINT32_MAX - 1, but this assumption is incorrect in other user namespaces created for instance for container environments. The uid mapping is de facto constant from within the user namespace and cannot be modified from inside (more precisely uid_map and gid_map proc files can only be written once each for a new user namespacE). netd makes the assumption that the uid mapping stays constant, meaning it is a bug if the host namespace tries to remap uids after netd starts. Bug: 110459356 Test: - built, - flashed and booted a marlin, 'fw_powersave' rule is as expected - flashed and booted ARC++ container, 'fw_powersave' rule is as expected - new unit tests pass Change-Id: I44a885c34e174b0067848b860be8d7b8f3e83296
* netd: Enable clang-tidy and fix all warningsBernie Innocenti2018-06-071-1/+1
| | | | | | Bug: 65246407 Test: m netd && system/netd/tests/runtests.sh Change-Id: I1d22b2bc317fe7218ccde78859ed0623d6a1f8df
* Rename <cutils/log.h> to <log/log.h>Logan Chien2018-04-231-1/+1
| | | | | | Bug: 78370064 Test: lunch aosp_walleye-userdebug && cd system/netd && mma Change-Id: I495f7cdc3f2aab26947f10041fc559700367f2ea
* Add xt_owner module support in trafficControllerChenbo Feng2018-04-121-1/+25
| | | | | | | | | | Add bpf maps for recording rules about socket owner uid filtering. Modified the bpf program so that packets with uid listed in the the uidOwnerMap will get handled according to userspace settings Test: bpf program can be loaded and attached when boot Bug: 72381727 30950746 Change-Id: I39497334fcb5e200dbf07a0046b85c227d59e2d7
* Migrate INetd String16 method to std::stringErik Kline2018-03-181-3/+3
| | | | | | | | | Test: as follows - built - flashed - booted - system/netd/tests/runtests.sh passes Change-Id: I7fe0e14a23b3c6f82dbfa17c7a44d221720976a0
* [ipsec-doze] Add fchown capabilities, and fw rulesBenedict Wong2017-12-181-0/+9
| | | | | | | | | | | Add some firewall rules to allow doze mode packets to be sent/received on ESP & no-socket packets. No-socket packets are no security risk because they are either forwarded, going to be forwarded, or will be dropped at routing tables (unless they are ESP). Bug: 62994731 Test: New tests added, run Change-Id: I2d8704498b564403d94123e4938091dee8fb98c1
* Allow connectivity-critical packets in data saver mode.Lorenzo Colitti2017-09-261-7/+14
| | | | | | | | | | | | | | This makes IPv6 work on metered wifi networks. Without this: 1. We reject incoming RAs, so we lose connectivity when the RA parameters expire. 2. We reject incoming NAs, so we get NUD failures. Bug: 66015813 Test: angler builds, boots Test: netd_{unit,integration}_test pass Test: CtsHostsideNetworkTests tests pass Change-Id: I033040ef0b91c22035e29c636123cd41ab1967ec
* Convert last FirewallController command to iptables-restore.Lorenzo Colitti2017-07-181-8/+23
| | | | | | | | | | | | This code currently has no callers, but it is the only remaining user of iptables in FirewallController. Move it to iptables-restore and delete support for iptables commands from the class. Bug: 28362720 Test: unit tests pass Test: adb shell ndc firewall set_interface_rule rmnet_data0 <allow|deny> Change-Id: I0a934283ca4479f870139d1ecf90096ae59eb19d
* Convert {enable,disable}Firewall to iptables-restoreLorenzo Colitti2017-07-171-10/+15
| | | | | | Bug: 28362720 Test: netd_{unit,integration}_test pass Change-Id: I7c3ddf0812f40124ac83f36d3fd3a8c595ce5472
* Move enableChildChains to iptables-restore.Lorenzo Colitti2017-04-281-15/+6
| | | | | | | | | | | | | | This saves 100-200ms on boot. (cherry picked from commit 0b64071d1326214b83e7dfb90701a4ee14ab6036) Bug: 37641280 Test: marlin builds and boots Test: new unit test passes Test: netd_{unit,integration}_test pass Test: fw_dozable added/removed from fw_INPUT/fw_OUTPUT on "adb shell dumpsys deviceidle <force-idle|unforce>" Change-Id: Iaa8daba011cf187d07526b2b85f9e9aba83adf4f Merged-In: Iabd2fa6ea260495feee3335b1605f3699b1722c5
* Reorder the commands in whitelist chains.Lorenzo Colitti2017-04-251-8/+16
| | | | | | | | | | | | | | | | | | | Currently FirewallController::replaceUidChain uses the same layout when building whitelist and blacklist chains: first it writes the exception rules (e.g., system apps, RST packets, ICMPv6 packets, etc.), and then the UIDs in the chain. This works, but it looks strange because unlike whitelist chains, insertion into whitelist chains always happens at the front of the chain. Make whitelist chains start with the UIDs, so that when UIDs are added at the beginning, they are contiguous to the UIDs that are already there. Bug: 32073253 Test: netd_{unit,integration}_test passes Test: bullhead builds, boots Test: fw_powersave chain looks sane Change-Id: I8a0ac7a33604455171b56e1d503cfe028a37a062
* Use IptablesRestoreController for UID rule updates.Lorenzo Colitti2017-04-251-16/+15
| | | | | | | | | Bug: 32073253 Test: netd_{unit,integration}_test passes Test: bullhead builds, boots Test: fw_powersave chain correctly updated when updating battery optimization whitelist Test: fw_powersave chain correctly updated when bringing apps into foreground Change-Id: I964b7664718f353057047c66e69351169b5cf453
* Merge "Remove unused CommandListener egress firewall cmds"Robin Lee2017-04-221-57/+0
|\
| * Remove unused CommandListener egress firewall cmdsRobin Lee2017-03-271-57/+0
| | | | | | | | | | | | | | | | | | These are gone from NetworkManagementService now Test: grep -sHRIF 'set_egress_' master # no results Test: make full -j30 # still builds Bug: 33159037 Change-Id: If8e3bfe3aecbadc4ead9643f907b62c45fbb91a0
* | Really always allow networking on loopback.Lorenzo Colitti2017-03-301-1/+2
|/ | | | | | | | | | | | | | https://android-review.googlesource.com/#/c/294359/ attempted to allow networking on loopback, but actually does not do anything because no packet has both -i lo and -o lo: loopback packets have -i lo in INPUT and -o lo in OUTPUT. Test: bullhead builds, boots Test: netd_{unit,integration}_test pass Test: loopback traffic is matched by new "-i lo" and "-o lo" rules Test: originated and received traffic is not matched by new rules Bug: 34444781 Change-Id: I090cbeafce5bbdcf36a7aecaafbf832feddc06e1
* Speed up FirewallController startup.Lorenzo Colitti2017-02-101-16/+7
| | | | | | | | | | | | | | | | | | | FirewallController::createChain runs iptables commands to remove the newly-created chain from fw_INPUT. This is not necessary, because createChain is only called from setupIptablesHooks, which is only called immediately after initIptablesRules, which clears fw_INPUT. So there is nothing to delete. Removing these unnecessary commands speeds up netd startup by ~150ms. Before: 02-03 18:51:40.075 492 492 I Netd : Setting up FirewallController hooks: 159.9ms After: 02-03 18:45:22.005 489 489 I Netd : Setting up FirewallController hooks: 11.3ms Bug: 34873832 Test: unit tests continue to pass Change-Id: I651d96a71c98d6aba989927cd23036d5cc371dd7
* Allow networking on loopback in doze, standby, and powersave.Lorenzo Colitti2016-07-281-0/+3
| | | | | | | | Restricting networking on loopback is needlessly restrictive because it doesn't have substantial power impact. Bug: 30186506 Change-Id: Ibe31aff7c43ae02821fdf4a00b600fb5f5f5bc30
* Silence spammy iptables rule at boot.Pierre Imai2016-05-271-1/+1
| | | | | BUG: 28529315 Change-Id: I4818b3833464502a44d9cdb92e3c59802882397b
* Make FirewallController::createChain use replaceUidChain.Lorenzo Colitti2016-05-161-28/+2
| | | | | | | | | | | | | | | | | | | | This has two benefits: 1. It makes the behaviour of setting firewall chains via the firewallReplaceUidChain RPC match the behaviour of creating the chains on boot. (As a side effect, it reduces code duplication between the two.) 2. It makes creating firewall chains on boot use iptables-restore, which is substantially faster than running iptables commands one at a time. This CL will allow the framework to switch to using firewallReplaceUidChain when the framework starts, providing substantial speedups over the current behaviour of running two iptables commands for every app that is whitelisted or idle. Bug: 26675191 Change-Id: Ifbd15bf9143efd526570dde8f88effc79d164630
* Make firewallReplaceUidChain match the behaviour of createChain.Lorenzo Colitti2016-05-161-12/+24
| | | | | | | | | | | | | | | | | | | | | The behaviour of the firewallReplaceUidChain was incorrect in several ways: 1. It was missing the "always allow TCP RST packets" rules which were added in http://ag/963000 . 2. It included a RETURN statement at the end of blacklist chains, which is superfluous since all user-defined chains implicitly return, and became incorrect when http://ag/963000 switched the behaviour of blacklist chains from inserting new rules at the beginning to appending them at the end. 3. It was missing the rules to allow the types of ICMPv6 packets that are critical in maintaining connectivity. By itself, this change is a no-op since nothing currently calls firewallReplaceUidRule. Bug: 26675191 Change-Id: I985e6861812908cbe7eaf0f54ca0ad39c22bbfeb
* Allow TCP RSTs to make it through firewall rules.Lorenzo Colitti2016-04-261-1/+13
| | | | | | | | This allows us to cleanly close apps' TCP connections when we remove their network connectivity. Bug: 27824851 Change-Id: I69ae0e860536139d30d14d580a36c82f79dc2f82
* Whitelist system apps when using bw_happy_box.Felipe Leme2016-03-141-3/+0
| | | | | | BUG: 27506285 BUG: 26685616 Change-Id: I8352ebbab1778c85e0a1da79a0acede5aea144a1
* Merge changes I2dc1a074,Ic83d8160,I246696c4 into nyc-devLorenzo Colitti2016-03-021-1/+41
|\ | | | | | | | | | | | | * changes: Move SockDiagTest into system/netd/server. Add an RPC to replace a UID firewall rule. Allow finer-grained locking, and use it in FirewallCmd.
| * Add an RPC to replace a UID firewall rule.Lorenzo Colitti2016-03-021-1/+41
| | | | | | | | | | | | | | | | | | Also add a binder_test that exercises binder RPCs to the real netd service running on the device Bug: 21725996 Bug: 27239233 Change-Id: Ic83d81605021a0578d6cd32f889290be61d76125
* | Created a firewall chain for power save mode.Felipe Leme2016-02-101-0/+13
|/ | | | | | | | | | | | | | | When power-save mode was first implemented, there were no firewall rules on netd, so the solution was to make all network interface metered and re-use the bw_penalty_box chain. This change removes that workaround by creating a explicit fw_powersave chain, whose behavior is similar to fw_dozable (in fact, it reuses some of its code); such change not only makes network restrictions on power-save mode simpler, but it also allows to optimze how the restrict network rules are changed. BUG: 27127112 Change-Id: I52aee49d80386594e3a52fea9667d580d2d944a1
* Don't break IPv6 connectivity when in doze mode.Lorenzo Colitti2015-09-021-0/+19
| | | | | | | | | | | | | Working IPv6 connectivity relies on the kernel being able to receive certain ICMPv6 packets (router advertisements, neighbour solicitations, neighbour advertisements) at all times. Allow these packets when in doze mode. This is not necessary for IPv4 because in IPv4 these functions use ARP, which is invisible to iptables. Bug: 23158230 Change-Id: I29ed77561db9688486cf58cd14ac3bce7fce4b40
* netd: add default fw white list for system uidsXiaohui Chen2015-06-251-0/+6
| | | | | | | | | In uid firewall white list, we white list the system uid range by default to make sure system processes will always have network access. BUG:22094135 Change-Id: I8f472a98a9fd93591a2887982cec1458d7683613
* netd: add two child chains to firewallXiaohui Chen2015-06-151-24/+113
| | | | | | | | | This is an attempt to speed up getting out of device idle. It groups uid firewall rules in these child chains so we can attach/detach a whole chain instead of individual uid rules. BUG:21446713 Change-Id: I61dc7d14110e633c5994e466481b9cac633a7a4f
* Blacklist uids for network accessAmith Yamasani2015-04-291-11/+38
| | | | | | | | | | | | | | | | | FirewallController can now be in blacklist mode (aka disabled) or whitelist mode (aka enabled). Some of the methods don't do anything when in blacklist mode. Uid rules updated to allow dropping packets to uids that shouldn't get any network access, usually for idle apps. Added a wait option to iptables calls to make sure it doesn't fail if there's contention. Fixes a flakiness I was seeing in removing rules. Bug: 20066058 Change-Id: I815bcb45aa06d04020e902df8c67bb3894e98f40
* server: check interface names in RPC arguments for validityJP Abgrall2014-06-191-0/+5
| | | | | | | | | | | | | | | | This patch introduces a method isIfaceName that checks interface names from various RPCs for validity before e.g. using them as part of iptables arguments or in filenames. All of these RPC calls can only be called from applications with at least the CONNECTIVITY_INTERNAL permission in recent Android versions, so the impact of the missing checks luckily isn't very high. Orig-Author: Jann Horn <jann@thejh.net> Change-Id: I80df8d745a3de99ad02d6649f0d10562c81f6b98 Signed-off-by: JP Abgrall <jpa@google.com>
* Move netd_client into netd.Sreeram Ramachandran2014-05-211-0/+149
Change-Id: Ie4b6b303225c93f2448a503d6ea9cebb552cbad5