Commit graph android_packages_modules_Co.../bpf
Message SHA1
NetBpfLoad: don't fail on S on kernels with buggy bpf arrays
Bug: 404427531
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ib30a731d7faecfc7e52590e28350c3289fe26852

Maciej Żenczykowski   commited 2025-04-02 17:53:30 -07:00
b3ddc8afad
Revert "bpf netd: no-op move lockdown check before iif match"
This reverts commit 837647cb74.

Reason for revert: not a no-op due to else

Change-Id: Iaaa4eb9a3f2c51714fd9fcf69cfd7ef2d125a309

Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-04-02 15:13:44 -07:00
2714fb5ce7
bpf netd: no-op move lockdown check before iif match
Flag: EXEMPT no-op
Bug: 338629178
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ifd46edfed99849290880aeb1ad26f70a6edad1ff

Maciej Żenczykowski   commited 2025-04-02 12:50:41 -07:00
837647cb74
Merge changes Ia6685d88,I64008821,I03238c72 into main
* changes:
  Store socket cookie to sk storage in inet_create hook on 5.10+ kernel
  Declare map with BPF_MAP_TYPE_SK_STORAGE
  Add macro to declare a sk storage and related accessor functions

Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2025-03-26 15:36:06 -07:00
dd430a186c
Store socket cookie to sk storage in inet_create hook on 5.10+ kernel
Test: adb logcat | grep inet_create on 4.19 and 5.10 kernel
Bug: 406080305
Change-Id: Ia6685d8827ea1570b950aff63bcae242e28ba637

Motomu Utsumi   commited 2025-03-26 09:25:37 +09:00
8fab64955b
Declare map with BPF_MAP_TYPE_SK_STORAGE
Test: adb logcat | grep sk_storage on 4.19 and 5.10 kernel
Bug: 406080305
Change-Id: I6400882146e8fd686a4260c5bf586a8f73032c71

Motomu Utsumi   commited 2025-03-26 09:25:37 +09:00
70793af736
Add macro to declare a sk storage and related accessor functions
Test: boot
Bug: 406080305
Change-Id: I03238c72e8024d4424c06803784988570513ff39

Motomu Utsumi   commited 2025-03-26 09:25:33 +09:00
d370f95f10
Merge "clatd bpf: drop multicast" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2025-03-25 15:39:25 -07:00
b45a61bc3f
clatd bpf: drop multicast
to avoid waking up clat daemon needlessly

(it just drops these anyway)

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

Maciej Żenczykowski   commited 2025-03-25 13:57:21 -07:00
aa33013ba5
NetBpfLoad: allow 25Q3
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com
Change-Id: Iced07b6438b4702334aaf85d301987efefe153c6

Maciej Żenczykowski   commited 2025-03-25 13:05:44 -07:00
3ac88f375b
Set BPF_F_NO_PREALLOC for BPF_MAP_TYPE_SK_STORAGE by default
BPF_F_NO_PREALLOC flag is mandatory for BPF_MAP_TYPE_SK_STORAGE

Test: boot
Bug: 406080305
Change-Id: I22f12525512ea8047ef5ad9fbf93490558c13c3d

Motomu Utsumi   commited 2025-03-25 10:18:15 +09:00
4364227e70
clatd: fix endianness of multicast drop
This is a *critical* fix for http://go/aog/3514294
  'Drop egress multicast on clat interface'

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

Maciej Żenczykowski   commited 2025-03-21 12:55:32 -07:00
30020a513a
Merge "NetBpfLoad: 25Q2+ parse & verify config" into main
Patrick Rohr   authored and   Gerrit Code Review   commited 2025-03-21 12:16:53 -07:00
b6d94ad6f3
NetBpfLoad: 25Q2+ parse & verify config
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ibe7560998655dfe36b5cc071a3405650ad684935

Maciej Żenczykowski   commited 2025-03-20 23:47:59 -07:00
25e2622121
Skip enabling BTF on kernel older than 5.10
BTF_KIND_VAR and BTF_KIND_DATASEC were introduced in 5.2.
It should be possible to enable BTF on 4.18 or above since libbpf can
load BTF.
Also, current code should work on 5.4 but this is untested.
For now, this CL enables BTF on 5.10 or above.

Test: boot on 4.9, 4.19, 5.10
Test: adb logcat | grep NetBpfLoad
Change-Id: I3da4970464afcf9a76b1f2645ed79c44750bcd6a

Motomu Utsumi   commited 2025-03-21 15:42:45 +09:00
861f11c9db
Fix an issue caused by variable re-declaration in inner scope
Since btf is declared in inner scope, btf is null in outer scope and BTF
was always disabled.

This CL also makes NetBpfLoad buildable with -Wshadow flag

Test: adb log | grep NetBpfLoad
Change-Id: I511f21a3620ccfdadd797786e087d0d142c816ed

Motomu Utsumi   commited 2025-03-21 15:40:42 +09:00
62b1c88367
Fix unsigned num comparison with zero
Caught by -Wtautological-unsigned-zero-compare compiler flag

Test: m
Change-Id: Ibedc657a237ba29fd7a4452271f347cd3180f57c

Motomu Utsumi   commited 2025-03-21 11:00:10 +09:00
a6ffae202b
Merge "netbpfload.rc: add a version comment" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2025-03-20 16:25:13 -07:00
1af58f3ad7
netbpfload.rc: add a version comment
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ifa37bf5e67f5c7ebc57430c272d74a5695e4ac58

Maciej Żenczykowski   commited 2025-03-20 16:24:48 -07:00
7782ab5f67
NetBpfLoad: 25Q2+ enforce 1GiB+ memlock
On at least some kernel versions sufficient memlock
is needed for some [types? larger? preallocated?]
bpf map creation requests to succeed.

(the kernel's bpf subsys ignores CAP_IPC_LOCK)

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

Maciej Żenczykowski   commited 2025-03-20 11:54:00 -07:00
ba7a418cab
Skip enabling BTF on kernel older than 4.18
BPF_BTF_LOAD command was introduced in 4.18

Bug: 403381101
Test: boot on 4.9 kernel
Change-Id: Ibf2070750334417bd1052486c1f59a5d3f7fc20c

Motomu Utsumi   commited 2025-03-19 19:49:08 +09:00
6f1ceccf14
NetBpfLoad: merge two map creation ALOGs
One ALOG to record whether the map is created by btf or not.

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

Maciej Żenczykowski   commited 2025-03-18 23:01:20 -07:00
9fef930ff1
Enable BTF for maps loaded by NetBpfLoad
Bug: 403381101
Test: boot
Change-Id: I05194e5a2678de07e3542aa744d2350a6d604ea2

Motomu Utsumi   authored and   Maciej Żenczykowski   commited 2025-03-18 12:15:39 -07:00
1a5cc5b57c
Add method to get key value type ids
BPF_ANNOTATE_KV_PAIR is used to tell the bpf loader about the btf
key_type and value_type of a bpf map.
This CL adds a method to get key value type ids from
BPF_ANNOTATE_KV_PAIR

Bug: 403381101
Test: boot
Change-Id: If308d49b64b38f65991a0a8177e5072d54e2cdf6

Motomu Utsumi   authored and   Maciej Żenczykowski   commited 2025-03-18 12:15:39 -07:00
59b2099360
Add method to load btf into kernel
Bug: 403381101
Test: boot
Change-Id: I9d5aedc13e7f4551eaa97b855496148b573c2176

Motomu Utsumi   authored and   Maciej Żenczykowski   commited 2025-03-18 12:15:39 -07:00
21536e55fc
Add method to update btf_var_secinfo.offset
Bpf loader needs to fix btf_var_secinfo.offset based on ELF's string
section.

Bug: 403381101
Test: boot
Change-Id: I8382d0ee3e0fa7f0a3b825eca9cdcf40ccce9532

Motomu Utsumi   authored and   Maciej Żenczykowski   commited 2025-03-18 12:15:39 -07:00
efe33319f7
Add method to update btf_type.size for BTF_KIND_DATASEC
size in btf_type of BTF_KIND_DATASEC is 0 at compilation time.
So bpf loader needs to update to actual size based on ELF's section
size.

Bug: 403381101
Test: boot
Change-Id: I78fb26a5b8eeb120044b5737667f472fac51d79f

Motomu Utsumi   authored and   Maciej Żenczykowski   commited 2025-03-18 11:46:16 -07:00
b3d3c2ae57
Enable libbpf logging in bpf loader
Bug: 403381101
Test: boot
Change-Id: I039ad8990bb722bfd6eb9f6c4d927b699475b7f6

Motomu Utsumi   authored and   Maciej Żenczykowski   commited 2025-03-18 11:41:17 -07:00
712088dff3
netd bpf: correct comment in NetBpfLoad S+ world (try 2).
fixup for https://android-review.git.corp.google.com/c/platform/packages/modules/Connectivity/+/3548759

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

Maciej Żenczykowski   commited 2025-03-17 22:49:56 -07:00
c07d271e54
netd bpf: correct comment in NetBpfLoad S+ world.
Bug: 404398959
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ieefac68fc531868cdf9aa4402cf8cb5a9d1a05ab

Maciej Żenczykowski   commited 2025-03-17 22:15:29 -07:00
4f373e3efa
Merge "Add libbpf version to bpf loader initial log" into main
Motomu Utsumi   authored and   Gerrit Code Review   commited 2025-03-06 02:32:19 -08:00
5977f5ce7c
Merge "Allow bpfloader to use libbpf" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-03-06 01:41:28 -08:00
fb8903013e
Merge "bpf: switch to mainline netbpfload on Android S/SV2" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2025-03-05 16:28:35 -08:00
7b7ab02f25
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: allow tagging non-tcp/udp sockets on T+ & 5.10+
Possible since inet_sock_release hook is now enabled on T+ 5.10+
and that will perform map cleanup for us without reliance on
netlink notifications (which aren't available for other types).

Test: atest netd_updatable_unit_test TagSocketTest, adbz_cookies
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I141b1f98ae8e4ce80813194a66a26755925b6683

Maciej Żenczykowski   commited 2025-03-05 14:19:48 -08:00
9aeb1f53cb
Revert "bpf: change NetBpfLoad rc file from 33 (T/U) to 31 (S/Sv2/T/U)"
This reverts commit 0e9b0e05c6.

Reason for revert: needs a .31rc specific version instead.
Will merge the required changes into the followup commit.

Change-Id: I01e9dfee4aaabc3ddab39da7519b7d9963b84124

Maciej Żenczykowski   commited 2025-03-04 21:54:09 -08:00
03bf18c028
bpf: change NetBpfLoad rc file from 33 (T/U) to 31 (S/Sv2/T/U)
By itself this change is a no-op, as we don't actually *yet* start mdnsd_netbpfload.

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

Maciej Żenczykowski   commited 2025-03-04 14:21:46 -08:00
0e9b0e05c6
bpf: rename BPFLOADER_MAINLINE_VERSION to BPFLOADER_MAINLINE_S_VERSION
This is a no-op.

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

Maciej Żenczykowski   commited 2025-03-04 14:20:29 -08:00
8c09778afe
Merge "bpf_map_def: undo incorrect comment change." into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2025-02-27 15:15:55 -08:00
40baa445a2
bpf_map_def: undo incorrect comment change.
This is a *partial* NOOP revert of:
 'bpf: support BPF_F_NO_PREALLOC in bpf_map_def.h'

https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/3457780

The comment is simply wrong, the negativeness is hidden
by the map declaration macros and thus never makes it
into the max_entries field of bpf_map_def struct.

A negative value passed to the map creation macros will store
the absolute value in max_entries, and set the BPF_F_NO_PREALLOC
flag in map_flags.

A negative / excessively large max_entries field will (presumably)
fail during map creation due to lack of ram.

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

Maciej Żenczykowski   commited 2025-02-27 14:26:52 -08:00
7c781b0b3c
Drop egress multicast on clat interface
Multicast packets on the clat interface are not supported,
so drop them in both clatd and its associated bpf offload.
This is required because NsdManager will start sending mDNS
packets on the clat interface as the check for
IFF_POINTOPOINT was removed.

Ingress multicast packets are already dropped elsewhere.

Test: TH
Change-Id: Icd22ca7f263ea5ff5244c17276ebb1002f72e842

Patrick Rohr   commited 2025-02-27 12:45:26 -08:00
bb08d8083e
Add libbpf version to bpf loader initial log
Test: build & boot
Bug: 394492034
Change-Id: Ic81b8c64074929d06736a8f55482cca53ca4b175

Motomu Utsumi   commited 2025-02-26 09:59:47 +09:00
a76935865b
Allow bpfloader to use libbpf
Test: m
Bug: 394492034
Change-Id: Ie99debe8786c4009f9ca4c42029837de1f0918ca

Motomu Utsumi   commited 2025-02-26 09:59:47 +09:00
79dbcf797b
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
NetBpfLoad: enforce eBPF is jitted on 25Q2+
Failure to jit means a buggy in kernel eBPF JIT implementation.

This cannot fail on a 64-bit kernel, because VINTF requires
kernel configuration option CONFIG_BPF_JIT_ALWAYS_ON.

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

Maciej Żenczykowski   commited 2025-02-14 11:22:13 -08:00
199fd35425
NetBpfLoad: 4.14+ fail hard on bpfGetFdProgId() failure
This should always work on 4.14+

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

Maciej Żenczykowski   commited 2025-02-14 11:18:18 -08:00
97debeb92b
BpfSyscallWrapper: add bpfGetFd{Jit,Xlat}ProgLen
Available in Linux Kernel 4.14+

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

Maciej Żenczykowski   commited 2025-02-14 11:12:31 -08:00
fb98f05e7c
NetBpfLoad: don't call bpfGetFdMapId in kernels < 4.14
The function is not available in older kernels.

But when we do call it, fail on error - should not happen.

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

Maciej Żenczykowski   commited 2025-02-13 16:10:48 -08:00
a003ace532
NetBpfLoad: int err -> const int err
for consistency with 3 other spots

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

Maciej Żenczykowski   commited 2025-02-13 16:05:07 -08:00
000f20ddcc