Commit graph android_packages_modules_Co.../bpf/tests/mts/bpf_existence_test.cpp
Message SHA1
bpf: remove obsolete isAtLeastR/Sv2/25Q3
We no longer support mainline on R,
hence checks for R are not required.

We don't want any S vs Sv2 and 25Q2 vs 25Q3 differentiation.

Test: TreeHugger
Flag: EXEMPT PURE_REFACTOR
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I746b404520ccb12fddf02c6956d7cf1824f21bbd

Maciej Żenczykowski   commited 2025-09-13 03:28:18 -07:00
8e730ec9e0
KernelUtils.h: isAtLeastKernelVersion(x,y,z) - default 'z' to 0
This seems to be the most common usecase.

Test: TreeHugger
Flag: EXEMPT PURE_REFACTOR
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2de4d067b2f20680539cbddb31555864bcf957b1

Maciej Żenczykowski   commited 2025-09-12 10:14:12 -07:00
ee24054e2b
bpf_existence_test - update for tcp acc ecn
(also tested with a hack to make isAtLeast26Q2 true)

Test: TreeHugger
Flag: EXEMPT TEST_ONLY
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id1ef5b03cdc27b6d74d6b5bd76692186809e9658

Maciej Żenczykowski   commited 2025-09-12 07:29:24 -07:00
82d68064e1
bpf_existence_test: remove support for Android R
As of M-2025-11 mainline is only being pushed to S+

Test: TreeHugger
Flag: EXEMPT test only
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id0cf9d2cce27fb90ce076fcdd0f6ee0a95ea9741

Maciej Żenczykowski   commited 2025-08-26 09:56:45 -07:00
1780108641
NetBpfLoad: create/populate/pin kernel bugs bpf array
This is an array of two ints:
- index 0 should have value 0
  (a value of 1 implies a kernel uapi bug)
- index 1 should have value 123
  (a value of 0 implies bpf array writes at non-zero index fail)

Note that these bugs can only be present on Android S & Sv2,
as these kernel bugs are considered fatal on Android T+.

(btw. we need to do this write manually as we cannot write into
maps we pin and then reopen - due to sepolicy)

Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9b2ada7f3e299014d39461a8d0718396daf0c91a

Maciej Żenczykowski   commited 2025-06-17 01:49:23 -07:00
83d5ad1d85
NetBpfLoad: Require Kernel 5.10 for Android 25Q4
Netd bpf requires 5.10 at least in 25Q4.
This CL enforces that.

Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I76e52b2a2702a2a6ce761a947a0749ea798778b6

Maciej Żenczykowski   commited 2025-05-06 05:28:23 -07:00
ec1115e46b
bpf: switch to mainline netbpfload on Android S/SV2
Test: TreeHugger, manually installing tethering apex
  (with and without dnsresolver apex) on pixel 6 running S
  incl. 'atest bpf_existence_test'
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I63d4b84287e9c98dc0d2a517ac58d3f3ce9d7760

Maciej Żenczykowski   commited 2025-03-05 14:27:59 -08:00
0b477491fb
bpf: move isAtLeastX to BpfUtils.h
Partially due to:
  https://android-review.googlesource.com/c/platform/bionic/+/3497280

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I74a626c45d641e226d7f71e00d0b542c5701417d

Maciej Żenczykowski   commited 2025-02-24 18:58:22 -08:00
732386394e
noop: change from deprecated __ANDROID_API_*__ to constants
See: https://android-review.googlesource.com/c/platform/bionic/+/3497280

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I8eb97fdae2a41962a646ee417890220efaa51c9f

Maciej Żenczykowski   commited 2025-02-18 15:13:31 -08:00
90400c5313
bpf netd: block local network calls if permission is not allowed.
Adding map local_net_blocked_uid_map, which will store uid for
the applications that have opted in but do not have the required
permission. The entry would be absent or the value would be false if the
application is allowed to access local network.

Test: Manually populating the values and checking EPERM error.

Bug: 390168818
Change-Id: Idf6caff204295a3f0aa7f552ea4af50bfd2df78c

Sarup Dalwani   authored and   Maciej Żenczykowski   commited 2025-01-22 17:14:10 -08:00
1aca8ee36a
bpf netd: Add local_net_access bpf map along with lookup method.
local_net_access is of type BPF_MAP_TYPE_LPM_TRIE (longest prefix
matching map) which stores interface index, remote address, protocol
and remote port. Lookup method is_local_net_access_allowed() returns
false if the arguments are found in the map and disallowed, otherwise
it returns true.

Test: Locally tested by adding values from userspace and querying the
bpf map.

Bug: 373608779
Change-Id: Ia34b3cb5613b56f6db5b224ec03f8c9909a49fe1

Sarup Dalwani   authored and   Maciej Żenczykowski   commited 2025-01-22 14:20:29 -08:00
26e05d4839
bpf: promote inet_release hook from V+ 5.10+ to T+ 5.10+
will land in M-2025-01

should fix some long standing cookie_tag_map full issues
(due to the userspace socket destroy listener code failing to run - likely due to buffer overflow)

Bug: 364365891
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: If78c335488eadf605a54f20005d9b14fdadb6473

Maciej Żenczykowski   commited 2024-09-23 20:21:40 +00:00
6e94583641
bpf: merge block.c into netd.c
Since this is just a special case of a bpf cgroup hook,
it really should be in netd.o with all other such hooks.

Besides moving/renaming the map & programs this should be a no-op.

Test: TreeHugger, atest bpf_existence_test
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I4a2aedaf77f89a9c0a96fa1c369d80659535eabe

Maciej Żenczykowski   commited 2024-09-19 00:40:53 +00:00
3ad3794efa
bpf: test.c - remove XDP program & add placeholder skfilter program
We're not currently using this XDP program, and it really only tests
bpfloader functionality, but with that being mainline it just doesn't
matter anymore.

It's not like we'll spontaneously decide to ever use XDP on devices
without some sort of per-device opt-in: too much could go wrong.

Unfortunately the Android S bpfloader has to be able to load test.o,
and it may fail if there is no prog section.
So we add a trivial 'placeholder' skfilter_match program, so that there
is at least 1 program in the file (and thus a 'prog' section exists).
Alternatively we could also probably just force an empty 'prog' section,
but this approach seems way easier...

Test: TreeHugger, atest bpf_existence_test
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I1d2fb8ceb33871c915d3f3d4fe6f2d811781a0c4

Maciej Żenczykowski   commited 2024-09-06 04:18:02 +00:00
9ba9c1dbb4
bpf: git mv tests/mts bpf/tests/mts
Another step towards moving all bpf related stuff into a common directory,
which will ease development.

I want to refactor this test so that it can also be run as a self-test
in UML (for testing bpfloading functionality across a large variety of
Linux kernel (both major and minor LTS) and Android (API/SDK level)
platform versions.

Bug: 205608149
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Idc9104783b2fa60626e9c1fd463c4d94fd4a908c

Maciej Żenczykowski   commited 2024-08-26 16:19:48 -07:00
548e35eb42
Renamed from tests/mts/bpf_existence_test.cpp (Browse further)