Commit graph android_system_bpf/bpfloader/BpfLoader.cpp
Message SHA1
limit types of bpf programs that platform and tethering apex can load
This is to prevent platform and tethering mainline module updatable
code from being to step on each other.

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

Maciej Żenczykowski   commited 2022-07-01 20:18:38 +00:00
ae58e7e4a7
bpfloader: support 'shared' maps and per-map/program selinux context
allow bpf .o files to specify desired selinux context

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

Maciej Żenczykowski   commited 2022-06-21 02:23:09 -07:00
4181713963
add support for 'netd_readonly'
For use by:
- maps netd should have read but not write access to
  (needed due to netd being root with DAC_OVERRIDE,
   and thus not obeying standard unix permissions)
- programs that netd should have access to but
  not netutils_wrappers (which due to being able to
  run iptables, needs access to xt_bpf programs)

Bug: 218408035
Test: booted on cuttlefish
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I72b106692a25077ff54252fd93db81f46b52125d

Maciej Żenczykowski   commited 2022-06-17 18:08:00 -07:00
32c0b8f46e
bpfloader: add support for netd_shared and net_private subdirs
Bug: 218408035
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I613b84342fba7b425fb10af157fe0a6a731b71cb

Maciej Żenczykowski   commited 2022-05-12 08:47:55 +00:00
7acf938127
move net_shared bpf programs into net_shared subdirectory
(no selinux consequences to this in and of itself,
 though required for follow up selinux changes)

Test: TreeHugger, manual
Bug: 218408035
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id5ef7f3b119743ef26b062068756c4e0f754e694

Maciej Żenczykowski   commited 2022-04-21 06:45:25 -07:00
2a36ce48b0
Add socket filter to allowed programs for vendor and remove tracepoint
This also fixes a permissions issue if a non-root user is set. The read
permissions should be set before the file is set as non-root to ensure
that the permissions can be set without error.

Bump the BPF loader version.

Bug: 203462310
Test: Ensure that vendor skfilter bpf programs can load
Change-Id: Ib6b9a64d8652ff464c9d4d734bb8ae351673b6ce

Stephane Lee   commited 2022-03-11 00:43:06 +00:00
16c9360b1f
bpfloader: also load from /vendor/etc/bpf/
Allow vendors to use bpf programs, but limit to tracepoints
for now (other types of programs, for instance skfilter, aren't
safe to expose, because the kernel gives us limited ways to
control which resources can have BPF programs attached, and
some shared resources only support a single BPF program at an
attach point).

Bug: 140330870
Bug: 162057235
Test: install bpf program to /vendor/etc/bpf/ and use it.
Test: atest libbpf_load_test
Change-Id: I6c876fe52739c38db73689ffd784167e7d35d58a

Steven Moreland   commited 2022-02-09 00:59:37 +00:00
0f10f3fd9f
bpfloader: use kernel logs
Boots early. logd no workie!

Bug: 210919187
Test: see bpfloader logs
Change-Id: Ib5669cb64684dfa18307ae5784349df3548d66d8

Steven Moreland   commited 2022-02-08 00:33:43 +00:00
a48639e39a
Allow bpfloader to handle 'net_shared' subdirectory
netd.c is moved from netd to tethering mainline module.

Bump BpfLoader to v0.9

Bug: 202086915
Test: cd system/netd; atest
Test: atest TrafficStatsTest NetworkUsageStatsTest
Change-Id: I0b8ba90bbbe4e16d979c4a40d6fdbbaac0d14d27

Ken Chen   authored and   Maciej Żenczykowski   commited 2022-01-19 04:18:53 +00:00
6d69784cdc
put tethering bpf maps & programs in /sys/fs/bpf/tethering/...
This makes it harder for system and mainline bpf programs to
conflict with each other, thus enabling easier mainline module
updates.

Test: builds and boots, atest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic1b69bb1ddc4a10bd4861dadbd6b97e2520c532d

Maciej Żenczykowski   commited 2021-01-20 05:17:14 +00:00
d8a4578f30
bpf is required for all devices running Android S
Test: builds, atest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie3f1146f71f75b982ffc4cd4176c5624efb6a63e

Maciej Żenczykowski   commited 2021-01-20 01:14:31 +00:00
f7a0a39d05
Load BPF programs from system and mainline folder
Test: flash and boot successfully
Change-Id: Ia1a713024686c36e34f7cf525a284abc00fe56e2

Hungming Chen   commited 2020-09-17 11:38:53 +08:00
4b8e982fae
bpfloader: sleep 20 seconds on failure
(should make it easier to observe logs via adb)

Test: atest, TreeHugger
Bug: 150040815
Bug: 160546011
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I20d6ede4ddf516a91c707aa08cf3a92aed39b03b

Maciej Żenczykowski   commited 2020-07-15 01:44:12 -07:00
07b874481f
Warn loudly and do not set bpf.progs_loaded property on critical bpf load failure.
Reasoning: critical load failures for netd bpf programs will just result
in unpredictable behaviour later on.  For example netd/systemserver
crash loops.

Test: builds
Bug: 150040815
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iefa01e60cd0a9a223e96411726a199bfb4857a5a

Maciej Żenczykowski   commited 2020-06-15 08:01:50 +00:00
89515d979a
only set 'bpf.progs_loaded' property on eBPF capable devices...
... which also means waitForProgsLoaded() has to be a no-op on pre-bpf devices.

This is more consistent: it's weird to have bpf.progs_loaded set on a 4.4 device.

Test: builds, atest
Bug: 150040815
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iddabcf56c187ea518dd2e4d8db451b2f6902aa8e

Maciej Żenczykowski   commited 2020-06-13 22:41:48 -07:00
567dc56b57
introduce isBpfSupported() helper
Test: build, atest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9e2a7e049746ad193eea01e7c9d6786d27728c72

Maciej Żenczykowski   commited 2020-02-11 15:05:27 -08:00
c3a640db94
bpfloader - remove dead code
Test: builds, atest
Bug: 146787904
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iea667cf4adaccdfd8fbffae8960cbe243ae77d70

Maciej Żenczykowski   commited 2019-12-30 04:12:36 -08:00
480c70ac14
bpfloader: Try to load even if bpf.progs_loaded is set
Currently the bpfloader does not try to load programs if
bpf.progs_loaded is set. However there is no harm in trying to reload
programs because the loader is designed to reuse previously created maps
and programs if they were created. On the other hand, not trying to load
if property is set is harmful since the property prevents retries. So
prevent this from happening.

Bug: 134558982
Change-Id: I61dfb8827ca37c9a1ff4e0912ca96f06a36c37d6
Signed-off-by: Joel Fernandes <joelaf@google.com>

Joel Fernandes   commited 2019-06-13 14:44:02 -04:00
2409604601
Skip bpf object loading on unsupported devices
The bpfloader should not try to load bpf objects on unsupported devices
since devices with 4.4 kernel can have bpf maps but not bpf pogram
support. Creating bpf maps on those devices would mislead the framework
code to use an unsupported code path and crash system server.

Bug: 130687855
Test: cuttlefish boot test for 4.4 kernel.
Change-Id: I43ffc01e1099ee3effaa6ba30aa78080d5bec72f

Chenbo Feng   authored and   Maciej Żenczykowski   commited 2019-04-17 21:40:39 +00:00
b20d28df6a
Remove bpfloader dependency on netd.
This was necessary when the netd BPF program lived in system/bpf,
but it's no longer necessary.

Test: m
Bug: 65674744
Change-Id: I1fcf7e41276341b1258adf9d3795e81b6139f84f

Lorenzo Colitti   commited 2019-03-26 13:52:15 +09:00
ac600729b8
Set bpf.progs_loaded property when programs finish loading
The property bpf.progs_loaded will be used by services expecting BPF
programs to be loaded and wait before they are loaded.

Bug: 112334572

Change-Id: I19daa0caa84e2659e8790f0dd551d95ab824e13b
Signed-off-by: Joel Fernandes <joelaf@google.com>

Joel Fernandes   commited 2019-01-11 09:02:11 -05:00
d3ec871017
New bpfloader netd kernel program
Change the netd bpf program to the new format. Adding map definition and
necessary helper functions to the kernel program code. Move the netd bpf
programs out of bpfloader to a new directory.

Test: dumpsys netd trafficcontroller
Bug: 112334572
Change-Id: I9287285d188e966193532b1522b5d3e67e32e930

Chenbo Feng   authored and   Joel Fernandes   commited 2019-01-07 20:17:42 -05:00
c1dd7648b1
Remove unused using decls.
Bug: 121209395
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,misc-unused-using-decls
Change-Id: I42d89c904c562ea2860510844c139b93ebee4637

Chih-Hung Hsieh   commited 2018-12-18 15:02:11 -08:00
18d8bfcfe9
Initial checkin for relocatable ELF loader and link with bcc
* Wrote a relocatable ELF loader from scratch. The loader library loads
all objects in /system/etc/bpf/, parses and fixes up eBPF instructions
based on relocation information, creates maps and programs and pins
them. A single API call without arguments is made which results in this
operation. The API has all the information it needs from the filesystem
and the ELF objects, so there is no configuration stored in the code
calling the loader API essentially making it zero conf. Initially this
will be used by time_in_state statistics collection using tracepoints.
In the future, netd's eBPF C code should be rewritten to use this
infrastructure and the old ELF loader can be gotten rid off. This is the
first step.

* Link libbpf with libbpf_android which will come from the external/ bcc
project. This will be used for tracepoint and perf eBPF support. In the
future it can be used for other things as kernel eBPF support advances.

This patch will be merged only after bcc is cloned into external/ to
prevent build breakage.

Bug: 112334572
Change-Id: Ic0fd9504e18031132d40bb627c5e44058d59c9f8
Signed-off-by: Joel Fernandes <joelaf@google.com>

Joel Fernandes   commited 2018-12-17 22:27:56 +00:00
d76a2004a6
Use size_t instead of unsigned int
Addresses follow-up review on commit fc3c769.

Test: m checkbuild
Change-Id: I79cd341c425ebe27cc66584540398fc98e94be50

Yi Kong   commited 2018-12-16 18:23:19 -08:00
4a74569453
Fix sign-compare warning
system/bpf/bpfloader/BpfLoader.cpp:79:23: error: comparison of integers of different signs: 'int' and 'std::__1::vector<android::bpf::BpfMapInfo, std::__1::allocator<android::bpf::BpfMapInfo> >::size_type' (aka 'unsigned long') [-Werror,-Wsign-compare]
    for (int i = 0; i < mapPatterns.size(); i++) {
                    ~ ^ ~~~~~~~~~~~~~~~~~~`

Test: m checkbuild
Change-Id: If2891bfc7655aea34499975763f72e0a25b32289

Yi Kong   commited 2018-12-14 14:31:42 -08:00
cb8e0a08ea
Code style clean up
Apply the git clang format on the bpf project to make sure the existing
code compliance with the standard.

Test: project compiles and bpfMapTest pass.
Bug: 112334572
Change-Id: I4774aa2a197be2c671f6fb307c1fc9b71edfeeec

Chenbo Feng   commited 2018-11-28 11:31:36 -08:00
1f20ad3d78
Fix the build problem with bpf project
Add the necessary Android.bp file and fix the compile error for the new
bpf project.

Fix the run time restart false alarm in bpf loader.

Bug: 112334572

Test: device boot and dumpsys netd show eBPF object okay, runtime
      restart netd and no bpfloader error showed in logcat.
Change-Id: Iae193bda45e50b7d22479086d6403e3c4fb185c4

Chenbo Feng   commited 2018-10-16 21:17:12 -07:00
4c9e9ecc57
Initial checkin for bpf project
Copied the files from system/netd into system/bpf. No modification is
made to the files.

Test: this doesn't build since the Android.bp file is missing
Bug: 112334572

Change-Id: Ia090a429dd416e07c46766784fb3dd2037201525

Chenbo Feng   commited 2018-10-16 20:38:03 -07:00
75b410bdf1