Commit graph android_packages_modules_Co.../bpf/netd
Message SHA1
mdnsd_netbpfload: reduce spam on failure
Test: TreeHugger
Bug: 408073256
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I698a4211cb32a11465de9e64932220a2bf464075

Maciej Żenczykowski   commited 2025-04-08 12:45:49 -07:00
b4d727e0ec
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
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
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
bpf: don't spam the log with initMaps successfully
We already log on init start, and we log all failures,
we don't need an extra log in the middle of init.

I NetdUpdatable: libnetd_updatable_init: Initializing
I NetdUpdatable: initMaps successfully
E NetdUpdatable: libnetd_updatable_init: Failed: (1) [Operation not permitted] : Failed to change RLIMIT_MEMLOCK to 2 GiB

while success looks like:
  I netd    : netd 1.0 starting
  I netd    : Pid file removed
  I netd    : SIGPIPE is blocked
  I netd    : setCloseOnExec(dnsproxyd)
  I netd    : setCloseOnExec(fwmarkd)
  I NetdUpdatable: libnetd_updatable_init: Initializing
  I NetdUpdatable: BPF programs are loaded
  I NetdUpdatable: initMaps successfully
  I netd    : libnetd_updatable_init success
  I netd    : NetlinkManager instanced

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

Maciej Żenczykowski   commited 2025-02-11 14:27:03 -08:00
6fc914642c
BpfHandler: more 'using' statements for bpf namespace
(it's a bit to pointlessly repetitive)

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

Maciej Żenczykowski   commited 2025-02-04 13:54:38 -08:00
7a7dcf824c
BpfHandler: reduce logging verbosity
most of these are spammy and/or not useful.

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

Maciej Żenczykowski   commited 2025-01-31 12:53:11 -08:00
0bcb13f41c
BpfHandler: add 25Q2+ netd map create and write test
Adding this to make sure we have 'unprivileged_bpf_disabled = 0'
This is currently set by NetBpfLoad, but if we remove that things currently work.

However with this change the device then fails to boot:
  $ adbz logcat -s -d *:* | egrep -i -C10 bpf
  I NetdUpdatable: libnetd_updatable_init: Initializing
  I NetdUpdatable: BPF programs are loaded
  I NetdUpdatable: initMaps successfully
  E NetdUpdatable: libnetd_updatable_init: Failed: (1) [Operation not permitted] : map create failed

This is because even though system/netd/server/netd.rc has:
  service netd /system/bin/netd
    class main
    capabilities CHOWN DAC_OVERRIDE DAC_READ_SEARCH FOWNER IPC_LOCK KILL NET_ADMIN NET_BIND_SERVICE NET_RAW SETUID SETGID
    user root
    group root net_admin

and we thus run as root/root with CAP_NET_ADMIN, but we do *NOT* have CAP_BPF nor CAP_SYS_ADMIN.
This means netd is considered 'unprivileged' from the point of view of that sysctl.

Creating maps from outside the bpfloader (ie. netd/system server/network stack)
is required for map-in-map.

While the sepolicy for netd.te map_create is in V, there is no real
need for this test on V atm, doing this to prevent *future* regressions.
A rollout purely to the not yet existing 25Q2+ is safer.

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

Maciej Żenczykowski   commited 2025-01-30 14:58:07 -08:00
48f244ece4
Check supported kernel version in V and 25Q2+
V requires 4.19+ and 25Q2+ requires 5.4+

(while 25Q4 will presumably further bump to 5.10+)

On aosp/main we currently have:
  ro.build.version.sdk=35
    - which is returned by android_get_device_api_level()
  ro.build.version.codename=Baklava
    - which is looked at by IsAtLeastPreReleaseCodename/GetCodename

This is because we're already past the aosp/main automerge into 25Q1 cutoff.

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

Maciej Żenczykowski   commited 2025-01-13 14:37:56 -08:00
1758f413a2
Remove BpfBaseTest processgroup test.
In practice this has to pass already due to netd_updatable
init attaching BPF_CGROUP_INET_{E,IN}GRESS programs.

This allows removing the processgroup shared lib dependency,
which should allow switching it from C to C++ mangling.

Thus we might be able to revert the revert (ie. reapply):
  https://android-review.googlesource.com/c/platform/system/core/+/3366140
in
  https://android-review.googlesource.com/c/platform/system/core/+/3369297

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

Maciej Żenczykowski   commited 2024-11-20 19:38:11 +00:00
eb85ea5f2a
BpfHandler: Add kver checks around V BPF attach program checks
Same as the netd change prior, but this is just to make it easier for
AOSP forks to work on legacy devices not meeting V requirements.

Change-Id: I2ebb479b6c9d3d82ee300bb6bf978184bb6c802b

LuK1337   commited 2024-11-04 18:49:24 +01:00
2918f066d5
BpfHandler: fix comment whitespace/quoting
Test: N/A
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I8823af530e3dad6d3646826a8d4537a8989c2efd

Maciej Żenczykowski   commited 2024-10-03 18:42:45 +00:00
e611324c50
netd_updatable: only wait for bpf on <=V
netd is after synchronous start of bpfloader,
so we don't actually need to wait for it at all.

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

Maciej Żenczykowski   commited 2024-10-02 22:53:03 +00:00
23c02b0b7f
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: git mv netd bpf/netd (plus update visibility for new path)
Another step towards moving all bpf related stuff into a common directory.

In practice netd_updatable is only actually used for bpf...

The upcoming netbpfload UML test should be checking netd_updatable's
initialization succeeds (useful since that opens a bunch of maps
fetches some programs, and attaches them to a bunch of cgroup hooks).

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

Maciej Żenczykowski   commited 2024-08-29 22:25:51 +00:00
04ed60fa25