Commit Graph

94 Commits

Author SHA1 Message Date
Maciej Żenczykowski
c8e40c149f flag test.o bpf program as being test only
Bug: 254543135
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I8ee7b0a552510baabb7c29d94521291b8b526692
2022-10-21 00:02:35 +00:00
Maciej Żenczykowski
be25f96390 offload.c - make tether_error_map read only.
Bug: 254543135
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I5d4c9cad66f59bd7eed54323ba72ea5a54ddf5e1
2022-10-20 04:08:03 +00:00
Maciej Żenczykowski
242af39425 dscpPolicy.c - old/new_first_u32 is actually be32
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I10b19a010000f1f49c2a48448f413376045bfe1f
2022-08-22 09:12:26 +00:00
Maciej Żenczykowski
0dd2bb31b6 split TCP control packet error into IPv4 vs IPv6
Bug: 241887405
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia155dbf7780b7bcff87e8fa6752d620ccbcae4a4
2022-08-10 19:34:35 +00:00
Maciej Żenczykowski
b82bf6502a split IP version mismatch error into IPv4 vs IPv6
Bug: 241887405
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6ff121ebaec26c9fe14ec8f4f7daebeff77eb7d1
2022-08-10 19:28:48 +00:00
Maciej Żenczykowski
640752bc4c dscpPolicy - sport is network endian, dport is host endian
be more consistent, and thus also less htons() calls

Test: TreeHugger, atest DscpPolicyTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia331a33a615a598e061db53ae180fffaef7a4342
2022-08-09 23:03:20 +00:00
Treehugger Robot
f39f7f83b0 Merge "dscpPolicy - remove bpf byteswap in favour of userspace" 2022-08-09 21:24:26 +00:00
Maciej Żenczykowski
285f705ced resolve nit from 'netd.c - update some permission related comments'
Test: TreeHugger
Bug: 236672779
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I5dcf6c32ef9bfd067afbfbbbd90e67ff678691f4
2022-08-09 17:50:46 +00:00
Treehugger Robot
2e922c3de4 Merge "netd.c - update some permission related comments" 2022-08-09 17:49:06 +00:00
Maciej Żenczykowski
a44510ba0c dscpPolicy - remove bpf byteswap in favour of userspace
Test: atest DscpPolicyTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7a008434d58fc0fba5b503eb6fcfbca15bb2015c
2022-08-09 14:59:46 +00:00
Maciej Żenczykowski
1feaa43cbb dscpPolicy - further improvements
Bug: 237485762
Test: atest DscpPolicyTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia88b14609cad4604523e3fc41860c980ee11abe0
2022-08-09 14:48:20 +00:00
Maciej Żenczykowski
06085b0425 netd.c - update some permission related comments
Test: TreeHugger
Bug: 236672779
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I66187d61ccdd3d625a9873090ab8c0dff18ac6a3
2022-08-09 14:15:59 +00:00
Maciej Żenczykowski
869c4ad452 Merge "update CRITICAL annotations for mainline" 2022-08-08 17:40:52 +00:00
Treehugger Robot
7623d8c799 Merge "No need for special case programs for [4.14, 5.4) kernels." 2022-08-05 22:52:17 +00:00
Maciej Żenczykowski
efe862e102 No need for special case programs for [4.14, 5.4) kernels.
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I428ea522b618e27eb65e8578f80f04232600af9a
2022-08-05 11:27:47 +00:00
Maciej Żenczykowski
c41e35d830 update CRITICAL annotations for mainline
(these only affect boot time logging)

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I3f315c5eabe73d3378e6ca0059f05221df7bab5e
2022-08-04 13:59:24 +00:00
Maciej Żenczykowski
c907fc73e9 Merge "Add libconnectivity_native_test_utils" 2022-08-01 18:24:33 +00:00
Ken Chen
f6d6b7e7de Merge "Move connectivity_native_test to a sub folder" 2022-07-29 01:55:30 +00:00
Ken Chen
c52cbe0cf8 Add libconnectivity_native_test_utils
The utility currently contains a firewall class that is used by DNS
resolver tests to block DNS packets.

Bug: 227159929
Test: atest resolv_integration_test
Change-Id: I5c5bc0b263a677f57cd63f002057ff0812f15e64
2022-07-29 03:53:24 +08:00
Ken Chen
ef50ab1473 Move connectivity_native_test to a sub folder
Move sources of connectivity_native_test to a dedicated folder so that
other native tests or utilities can be added to p/m/c/tests/native/ as
well.

Bug: 227159929
Test: atest connectivity_native_test
Change-Id: I97217fbb03b26ed79f1f34932b92c4227a1ece4d
2022-07-28 14:41:23 +08:00
Maciej Żenczykowski
d7b92c03e9 dscpPolicy.c - cache result-less lookups as well
It is most definitely worthwhile to cache negative lookups as well!

Test: TreeHugger, atest DscpPolicyTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iab1a57a2611a891642fef0c5897918c16e0ca540
2022-07-27 16:20:51 -07:00
Maciej Żenczykowski
f75b7e199a dscpPolicy.c - increase size of cache map
(and merge the ipv4 and ipv6 caches into one,
as there really is no need for separate ones)

Test: TreeHugger, atest DscpPolicyTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie62393ea428885076ef59af69ac3eafeeba2934f
2022-07-27 16:20:40 -07:00
Maciej Żenczykowski
0ff4ec058b dscpPolicy.c - remove spurious map A/B
The 'switch_comp_map' is never written to,
hence map A is always used anyway...

Additionally this is backwards - ie. the *wrong* maps were A/B:
it is not the cache that should be A/B but rather the policy map(s).

This simplification has the nice benefit of making the program
much simpler and thus presumably optimizing bpf verifier processing
and thus bpfloader runtime during boot.

The fact that these socket cache maps are never cleared from userspace
is a different bug that needs to be fixed.

Bug: 235559605
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic2b0d20cd4e9e7290fb9fae38e1625ea1ed85a78
2022-07-27 16:20:40 -07:00
Tyler Wear
4e8949b216 DscpPolicy Optimize skb store bytes
Use a single skb store bytes for IPv6 instead of 2 api
calls for 2 uint8_t values, use 1 for a single uint32_t value.

Bug: 234808633
Change-Id: I31ecc6d7036fd71b10c60d320c1dc5ebf0b86cca
2022-07-26 13:10:54 -07:00
Patrick Rohr
7f325ccccb DscpPolicy: match_policy is_eth is always true
The raw IP program was removed, so there is no need to support it
anymore in match_policy().

Test: TH
Bug: 235559605
Change-Id: I755a9a55e3ad33a210145b2cc09578fdf4d66c79
2022-07-25 13:31:14 -07:00
Patrick Rohr
51cf563115 DscpPolicy: remove bpf support for raw ip
This program was only used for tests as WiFi interfaces should always
include an ethernet header. Since the test has moved from tun to tap,
this can be deleted.
Support for using this program was already removed in a previous CL.

Test: TH
Bug: 235559605
Change-Id: I2148bce60992070790ba237176b99a40597ee751
2022-07-25 13:31:14 -07:00
Ken Chen
74ff3ee501 Rename dscp_policy.o to dscpPolicy.o
Underscore character may cause bpf prog/map naming collision. For
example, x.o with map y_z and x_y.o with map z both result in x_y_z
prog/map name, which should be prevented during compile-time.

aosp/2147825 will prohibit underscore character in bpf source name
(source name derives the obj name). Existing bpf modules with underscore
characters in source name need to be updated accordingly.

Bug: 236706995
Test: atest bpf_existence_test
Test: adb root; adb shell ls -l sys/fs/bpf/net_shared | grep dscpPolicy
Change-Id: Ibe98944d09d42bd11b78b5e9ae35ded48c70416d
2022-07-21 21:00:09 +08:00
Treehugger Robot
81ee9c4f1a Merge "DscpPolicy BPF Rename Field Names" 2022-07-20 13:07:28 +00:00
Maciej Żenczykowski
ccce4a3382 offload/test bpf: support InProcessTethering
InProcessTethering runs as system_server (uid/gid AID_SYSTEM)
instead of as the network_stack (uid/gid AID_NETWORK_STACK).

Additionally only the network_stack has access to the default
selinux context of /sys/fs/bpf/tethering, which is fs_bpf_tethering,
so we need to use 'fs_bpf_net_shared' instead.

Bug: 190523685
Bug: 236925089
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ibb6ae255dcd8a8e8049be112055f60c3b2cf7df0
2022-07-18 09:05:32 -07:00
Maciej Żenczykowski
07d3013b0d enable btf for offload.o & test.o
The objdump -x visible changes between old and new versions of the
mainline shipped .o files are really very minimal: just the inclusion
of a new .BTF section and changes/removals of some 'l' entries from
the symbol table.  However, it turns out a change to symbol ordering
is incompatible with BpfLoader <v0.10 which doesn't know to skip
non-function symbols, and as such enabling btf requires a little
bit of gymnastics.

After:
  $ adbz shell ls -l /apex/com.android.tethering/etc/bpf/*.o
  -rw-r--r-- 1 system system 118352 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/offload.o
  -rw-r--r-- 1 system system 123424 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/offload@btf.o
  -rw-r--r-- 1 system system   2232 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/test.o
  -rw-r--r-- 1 system system   6376 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/test@btf.o

$ adbz shell logcat -d | egrep offload.*[.]o
07-15 13:10:43.358     0     0 D LibBpfLoader: Loading critical for tethering ELF object /apex/com.android.tethering/etc/bpf/offload.o with license Apache 2.0
07-15 13:10:43.359     0     0 I LibBpfLoader: BpfLoader version 0x00019 ignoring ELF object /apex/com.android.tethering/etc/bpf/offload.o with max ver 0x00019
07-15 13:10:43.359     0     0 I bpfloader: Loaded object: /apex/com.android.tethering/etc/bpf/offload.o
07-15 13:10:43.374     0     0 D LibBpfLoader: Loading critical for tethering ELF object /apex/com.android.tethering/etc/bpf/offload@btf.o with license Apache 2.0
07-15 13:10:43.375     0     0 I LibBpfLoader: BpfLoader version 0x00019 processing ELF object /apex/com.android.tethering/etc/bpf/offload@btf.o with ver [0x00019,0x10000)
07-15 13:10:43.452     0     0 D LibBpfLoader: map_fd found at 0 is 6 in /apex/com.android.tethering/etc/bpf/offload@btf.o
...

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id658818d1d42763358747523615b7918d312588e
2022-07-16 05:35:15 +00:00
Tyler Wear
9228105917 DscpPolicy BPF Rename Field Names
Rename field names to all be the same convention.

Bug: 234808633
Change-Id: I79888d46fac273f5a22bfbc231f065e0d7f9cb72
2022-07-13 16:52:43 +00:00
Tyler Wear
11f494faa6 DscpPolicy BPF IPv4 Checksum Offset, DSCP Value Storage
Use the correct offset for the eth header when calculating the
checksum.

Store the DSCP value in BPF map for subsequent skb's instead
of the TOS so the calculation and checksum is correct.

Bug: 234808633

Change-Id: Ib40d4575455f34a8970eca8751b590319e2ee1ad
2022-07-11 13:13:57 -07:00
Tyler Wear
a8ca597aec DscpPolicy Move to kernel 5.15
Require at least kernel 5.15. Feature is not required on older
kernels and may impact boot time unnecessarily.

Bug: 235559605
Change-Id: I2e4b509de1d8940fc63ae057a8326f13c0fd1420
2022-06-30 19:41:03 +00:00
Motomu Utsumi
6421d8456c Merge "Add API to get current firewall chain status" 2022-06-27 05:43:46 +00:00
Motomu Utsumi
be3ff1e923 Add API to get current firewall chain status
This commit adds ConnectivityManager#getFirewallChainEnabled to read the
current firewall chain status

Bug: 208371987
Test: m
Change-Id: I1eadb69f953af5d031cd8dabde3e1f098cf0f4df
2022-06-24 09:11:53 +00:00
Maciej Żenczykowski
cae181d777 netd bpf program - use finer grained selinux privs, part 1
Make use of new BpfLoader functionality: per-map/program selinux context
to further restrict access to mainline module shipped bpf maps and programs.

Bug: 218408035
Test: booted on cuttlefish, TreeHugger
Change-Id: Iaa33754aaca8bfafef6539abfbdd30b4cdfc4727
2022-06-18 18:59:12 -07:00
Maciej Żenczykowski
1c52aa12e8 switch netd.o to BpfLoader v0.18 file format
This is a temporary thing for testing with framework/libs/net patch
that adds checks for V18 define.

This is very short term and will be reverted in the next topic,
that will make v0.18 the default.

Bug: 218408035
Test: booted on cuttlefish
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I22c414ebc64201db60eb872e0da0fea6c65eaede
2022-06-17 16:13:56 -07:00
Maciej Żenczykowski
b0adaec487 Revert "switch netd.o to BpfLoader v0.18 file format"
This reverts the previous commit.

This is no longer required as v0.18 is now the default.

Test: Treehugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9331f27cf20e7932f6ef0e3829c27b6684dece59
2022-06-17 16:13:56 -07:00
Maciej Żenczykowski
a899aa253a Merge "switch netd_configuration_map from hash map to array" 2022-06-16 23:54:15 +00:00
Maciej Żenczykowski
b10e055f4b switch netd_configuration_map from hash map to array
This eliminates the need for netd_updatable BpfHandler.cpp
to initialize the hash map with a zero.

On startup the map will be freshly initialized and thus zero.

On restart it might not be empty, but it doesn't matter to netd.
Furthermore the mainline component of the system server will
re-initialize it again anyway:
see service/native/TrafficController.cpp initMaps()

This does remove the ability to call deleteValue on a key,
since that would always return -EINVAL, but since we don't
currently do that, that's really a feature.

(It does suggest though that we should have a BpfMapNonNullable
 class which is writeable, but without a deleteValue() function)

Additionally BpfMap arrays are more efficient for the kernel bpf jit
compiler, as - on newer kernels - it can optimize the read/write
into a simple memory access (as opposed to a bpf helper call).

Before:
  $ adb shell ls -l /sys/fs/bpf/netd_shared/map_netd_configuration_map
  -rw-rw---- 1 root net_bw_acct 0 2022-06-11 08:20 /sys/fs/bpf/netd_shared/ map_netd_configuration_map

After:
  $ adbz shell ls -l /sys/fs/bpf/netd_shared/map_netd_configuration_map
  -r--rw---- 1 root net_bw_acct 0 2022-06-16 15:03 /sys/fs/bpf/netd_shared/map_netd_configuration_map

Bug: 235590615
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I21730e4fa22fbf0c94ab0ca5c5db03aa000b7680
2022-06-16 22:53:42 +00:00
Maciej Żenczykowski
ce9108f01a verify CLAT_MARK matches aidl constant.
Bug: 235778483
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ife3ad35b2e5451727a3795a0e78dd820293c0eae
2022-06-16 21:39:32 +00:00
Lorenzo Colitti
7f0bdd3bfe Merge "move XtBpfProgLocations.h into a new header library" 2022-06-16 03:18:20 +00:00
Maciej Żenczykowski
fa2b1dc6b0 fix minor whitespace nit
Test: N/A
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: If472cdec22b04f605f40b680c907a3384dce3cdc
2022-06-15 16:15:27 +00:00
Maciej Żenczykowski
200d372dc9 move XtBpfProgLocations.h into a new header library
Bug: 235778483
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia5e3c72e65cee17ef67907008d8fe6d4e47050de
2022-06-15 03:17:40 -07:00
Maciej Żenczykowski
b909d8af55 bpf_progs - eliminate netd.c dependency on UidConstants.h
Per Lorenzo's request on:
  https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2123888

Bug: 235778483
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id464fc2418efcb3764fae2a25c11fdda4439f411
2022-06-15 00:59:20 -07:00
Maciej Żenczykowski
1205737641 assert that xt_bpf programs match Android T netd's expectations
Bug: 235778483
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic0029063e4dbbf1b2cce7d7ca86a017a1c56f072
2022-06-14 20:33:54 -07:00
Treehugger Robot
fb0fe32e6d Merge "remove no longer needed bpf_connectivity headers visibility" 2022-06-14 08:19:33 +00:00
Maciej Żenczykowski
5f5d2e2c10 remove no longer needed bpf_connectivity headers visibility
Bug: 235778483
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I3829ba49e453918bfcbae2e07dd2aea2b81e12bf
2022-06-14 06:03:15 +00:00
Maciej Żenczykowski
a4a58a3be2 netd.c - reduce privs on maps
Before:
  $ adb shell ls -l /sys/fs/bpf/netd_shared/map_netd_*
  -rw-rw---- 1 root net_bw_acct 0 2022-06-11 08:17 /sys/fs/bpf/netd_shared/map_netd_app_uid_stats_map
  -rw-rw---- 1 root net_bw_acct 0 2022-06-11 08:17 /sys/fs/bpf/netd_shared/map_netd_configuration_map
  -rw-rw---- 1 root net_bw_acct 0 2022-06-11 08:17 /sys/fs/bpf/netd_shared/map_netd_cookie_tag_map
  -rw-rw---- 1 root net_bw_acct 0 2022-06-11 08:17 /sys/fs/bpf/netd_shared/map_netd_iface_index_name_map
  -rw-rw---- 1 root net_bw_acct 0 2022-06-11 08:17 /sys/fs/bpf/netd_shared/map_netd_iface_stats_map
  -rw-rw---- 1 root net_bw_acct 0 2022-06-11 08:17 /sys/fs/bpf/netd_shared/map_netd_stats_map_A
  -rw-rw---- 1 root net_bw_acct 0 2022-06-11 08:17 /sys/fs/bpf/netd_shared/map_netd_stats_map_B
  -rw-rw---- 1 root net_bw_acct 0 2022-06-11 08:17 /sys/fs/bpf/netd_shared/map_netd_uid_counterset_map
  -rw-rw---- 1 root net_bw_acct 0 2022-06-11 08:17 /sys/fs/bpf/netd_shared/map_netd_uid_owner_map
  -rw-rw---- 1 root net_bw_acct 0 2022-06-11 08:17 /sys/fs/bpf/netd_shared/map_netd_uid_permission_map

After:
  $ adb shell ls -l /sys/fs/bpf/netd_shared/map_netd_*
  ----rw---- 1 root net_bw_acct 0 2022-06-13 18:17 /sys/fs/bpf/netd_shared/map_netd_app_uid_stats_map
  -rw-rw---- 1 root net_bw_acct 0 2022-06-13 18:17 /sys/fs/bpf/netd_shared/map_netd_configuration_map
  -rw-rw---- 1 root net_bw_acct 0 2022-06-13 18:17 /sys/fs/bpf/netd_shared/map_netd_cookie_tag_map
  ----rw---- 1 root net_bw_acct 0 2022-06-13 18:17 /sys/fs/bpf/netd_shared/map_netd_iface_index_name_map
  ----rw---- 1 root net_bw_acct 0 2022-06-13 18:17 /sys/fs/bpf/netd_shared/map_netd_iface_stats_map
  -rw-rw---- 1 root net_bw_acct 0 2022-06-13 18:17 /sys/fs/bpf/netd_shared/map_netd_stats_map_A
  -r--rw---- 1 root net_bw_acct 0 2022-06-13 18:17 /sys/fs/bpf/netd_shared/map_netd_stats_map_B
  ----rw---- 1 root net_bw_acct 0 2022-06-13 18:17 /sys/fs/bpf/netd_shared/map_netd_uid_counterset_map
  ----rw---- 1 root net_bw_acct 0 2022-06-13 18:17 /sys/fs/bpf/netd_shared/map_netd_uid_owner_map
  -rw-rw---- 1 root net_bw_acct 0 2022-06-13 18:17 /sys/fs/bpf/netd_shared/map_netd_uid_permission_map

Access required is based on list of maps at netd/BpfHandler.h:62
  BpfMap<uint64_t, UidTagValue> mCookieTagMap;
  BpfMap<StatsKey, StatsValue> mStatsMapA;
  BpfMap<StatsKey, StatsValue> mStatsMapB;
  BpfMap<uint32_t, uint32_t> mConfigurationMap;
  BpfMap<uint32_t, uint8_t> mUidPermissionMap;

Note that this is still just a first stab at things.
The only one which should really be writable is mCookieTagMap,
but that's for follow ups as it gets real difficult to switch
due to the tests and BpfMap vs BpfMapRO inheritance inversion.

Additionally due to netd being root with CAP_DAC_OVERRIDE,
this change is really a no-op, and will be until we add
proper per map selinux contexts.  So it is in a sense only
a documentation of intent change...

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I86f3028251818c2025503839c7225d07a2943ed0
2022-06-13 19:39:06 -07:00
Maciej Żenczykowski
474512ac7a netd.c: Simplify bpf_owner_match
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7ab02c868eeeadf17c06f2c35505c4891c1b48b7
2022-06-08 22:23:12 +00:00