Commit graph android_system_bpf/progs
Message SHA1
add support for marking ebpf programs as being only for some kernel versions
Some ebpf code cannot be loaded on too old kernels.

Sometimes we want a different - more advanced - version of an ebpf program
to be loaded on a newer kernel.

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

Maciej Żenczykowski   commited 2020-02-19 15:46:23 -08:00
07375e26a3
Pull AID_* constants from shared location.
Test: build, atest
Bug: 149434314
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iadfc7fbbfcb561e7cfafaa5806939c9f69f43d59

Maciej Żenczykowski   commited 2020-02-18 15:21:35 -08:00
56bf76bbab
add DEFINE_BPF_MAP_GWO macro for group write-only maps
Test: build, atest
Bug: 138317993
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0b2bed9eb94e0aeaca79b5476c6e91484c7e1847

Maciej Żenczykowski   commited 2020-02-18 14:30:39 -08:00
62a4dddbba
bpfloader: add option to set owner & group for pinned programs
Unlike maps, BPF programs currently have no natural place to declare
metadata like their desired owner & group. Add a bpf_prog_def struct
to allow setting these, located in a new "progs" section, and update
bpfloader to chown pinned programs appropriately based on this
information.
Add a #DEFINE_BPF_PROG macro to simplify adding this data for
programs. The struct name is the name of the corresponding function
with "_def" appended, which bpfloader uses to correlate a bpf_map_def
with the correct program.
Also have bpfloader set mode to 0440 for all programs, since only read
access should ever be needed

Bug: 149434314
Test: load a program that uses DEFINE_BPF_PROG and check that owner &
group are set as expected
Change-Id: I914c355f114368fe53de2c7f272d877463cba461
Signed-off-by: Connor O'Brien <connoro@google.com>

Connor O'Brien   authored and   Maciej Żenczykowski   commited 2020-02-14 23:28:44 +00:00
3278a1634b
add bpf_map_def support for setting uid/gid/mode
Test: build, atest, adb shell ls -lZ /sys/fs/bpf
Bug: 149434314
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie4001fbe16b4bc84fc8ec7138ae4928cd86f5ce7

Maciej Żenczykowski   commited 2020-02-14 23:28:26 +00:00
83f2977da8
bpfloader - add AID_* constants to bpf_map_def.h
Test: build, atest
Bug: 149434314
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I607f304a7e7bd76b8ce33489f9e239596f4d7398

Maciej Żenczykowski   commited 2020-02-14 23:27:45 +00:00
6f87896bdf
refactor bpf_map_def into a single header file
Test: build, atest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iafd6016f4f24cc8fa263939c67e1a096aa91b125

Maciej Żenczykowski   commited 2020-01-29 08:41:26 +00:00
730a3860c2
bpf_helpers - add more const annotations
Keys and values passed in to lookup/update/delete are not modified.

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

Maciej Żenczykowski   commited 2020-01-24 18:53:10 -08:00
0bfbf665b9
bpf: move time in state struct definitions into a single shared header
Key and value formats for time in state related BPF maps currently
have to be kept in sync between the BPF prog and
libtimeinstate. Add a new bpf_timeinstate.h header file in a directory
that already gets added to the include path for BPF progs, and add
this file to a cc_library_headers module so it can be used from
libtimeinstate as well.

Test: build libtimeinstate and time_in_state.o
Bug: 138317993
Change-Id: Ic56b2b64746f2211f3c802e074339750f26303c0
Merged-In: Ic56b2b64746f2211f3c802e074339750f26303c0
Signed-off-by: Connor O'Brien <connoro@google.com>
(cherry picked from commit badb20f528)

Connor O'Brien   authored and   Maciej Żenczykowski   commited 2019-11-13 21:58:27 -08:00
85087ae737
move networking bpf helpers to system/netd
Test: build, atest
Bug: 141532657
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: If7b13a80d3db07da7c540dc7661e92ea8e0ad8c8

Maciej Żenczykowski   commited 2019-10-31 01:04:49 -07:00
2ff3b5c0f4
bpf_helpers.h - change unsafe_bpf_map_* to bpf_map_*_unsafe
Test: treehugger will, plus no other references found by:
  repo grep 'unsafe_bpf_map_(lookup|update|delete)_elem'
Bug: 132703771
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I59b8fe8f5a00fd005f466f8f2177a2e01cff58aa

Maciej Żenczykowski   commited 2019-05-14 14:48:58 -07:00
c1d2e029f4
Reapply "Provide a macro to define a map along with type safe accessors"
This reverts commit 4f3298db93.

Change-Id: Ibf410a56ec69ccc2c14591edcc8b9ede2a410bb4

Maciej Żenczykowski   commited 2019-04-20 11:02:33 +00:00
28296961f6
Revert "Provide a macro to define a map along with type safe accessors"
This reverts commit 6564b8eac4.

Maciej Żenczykowski   commited 2019-04-19 21:46:04 -07:00
4f3298db93
Provide a macro to define a map along with type safe accessors
Test: atest libbpf_android_test libnetdbpf_test netd_integration_test netd_unit_test netdutils_test resolv_integration_test resolv_unit_test
Bug: 130746652
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ib7a351ff876891a2296e32deebd0308ff9c7fcc8

Maciej Żenczykowski   commited 2019-04-19 11:14:24 -07:00
6564b8eac4
Add support for the bpf_probe_read_str bpf function
This is needed for the iorapd project (i/o readahead).

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

Joel Fernandes   commited 2019-04-17 15:37:18 +00:00
1b8962af4c
bpf_helpers.h - define more kernel provided functions
Test: builds
Bug: 65674744
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I88dcaf5edf61b780666f346e963a7417c04c97ec

Maciej Żenczykowski   commited 2019-04-02 04:04:02 -07:00
e1153fd1da
Move netd specific program back to netd
For the eBPF programs that only related to networking, move them back
to netd so for the future changes in networking eBPF area, there is not
need to make changes in both netd project and bpf project.

Bug: 112334572
Test: mmma -j32 system/bpf
Change-Id: Icd0efd165c60c055a00fe88705a0c8070c0d22f5

Chenbo Feng   commited 2019-02-26 15:41:00 -08:00
47e92158ca
netd: Use common BPF helper for C program
The BPF helper is moved into system/bpf/include/ and is available
to all BPF programs in the include search path. Make use of it.

Only minor refactor, no functional change.

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

Joel Fernandes (Google)   authored and   Joel Fernandes   commited 2019-02-12 17:20:20 -05:00
14ba88881f
Add bpf program to control socket creation
For new kernel that support cgroup socket filter, use bpf programs to
control the creation of inet socket.

Bug: 111560570
Bug: 111560739
Test: dumpsys netd trafficcontroller
Change-Id: I94efcdccfcd17f08c731caa700ea5797f2f56e7d

Chenbo Feng   commited 2019-01-29 18:58:03 -08:00
ef6d45e7cf
Add cgroup socket bpf kernel program support
Add support for cgroup socket filter program loading in bpfloader,
and create a uid permission map to store the uids that have INTERNET
permission.

Bug: 111560570
Bug: 111560739
Test: dumpsys netd trafficcontroller

Change-Id: I658f533d302cb594d7b36d4a3a2a70e394874c33

Chenbo Feng   commited 2019-01-28 15:21:59 -08:00
5aee2f14a5
Do not take cumulative network stats anymore
Use two maps to record the details of network stats and swap and clean
up after system server pulls the stats. The kernel program checks the
bpf map currently enabled before updating the stats and updates on the
corresponding map. Remove the TAG_STATS_MAP since we don't need to worry
about uid stats overflow problem. All the stats can be stored in the
same map until system server scrapes the stats and clean it up.

Bug: 79171384
Test: dumpsys netd trafficcontroller
      CtsUsageStatsTestCases

Change-Id: Ic79e382f51bf21eee78c4cac5a8a97edaf3654cd

Chenbo Feng   commited 2019-01-22 18:40:10 -08:00
9cd8f14ed0
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