Commit graph

467 commits

Author SHA1 Message Date
Treehugger Robot
e9e8305a36 Merge "BpfMap - make clear() multithread safe" 2020-02-20 13:05:14 +00:00
Automerger Merge Worker
c59638c5c4 add support for marking ebpf programs as being only for some kernel versions am: 07375e26a3 am: fdc1c2ff8e
Change-Id: I670bb4bd205a61d6ef3d7a86b5f0173d1e26b3c5
2020-02-20 03:02:17 +00:00
Automerger Merge Worker
fdc1c2ff8e add support for marking ebpf programs as being only for some kernel versions am: 07375e26a3
Change-Id: Ia8b49d34c148f83f90a19625c095928de0b25dc8
2020-02-20 02:50:02 +00:00
Maciej Żenczykowski
07375e26a3 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
2020-02-19 15:46:23 -08:00
Maciej Żenczykowski
b7176fb6af BpfMap - make clear() multithread safe
(while at it also remove 3 spurious this-> prefixes)

Test: build, atest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2419926b555734d7f5e052fb9e0686c52bdb32d0
2020-02-19 13:29:02 -08:00
Automerger Merge Worker
a90f74c721 Remove bpfloader dependency on netd's ebpf programs. am: cd994cd637 am: 74034ba0d9
Change-Id: Id19c303cdb4a5197a1638b4b2207469ec74fca2d
2020-02-19 20:19:43 +00:00
Automerger Merge Worker
74034ba0d9 Remove bpfloader dependency on netd's ebpf programs. am: cd994cd637
Change-Id: I98dbddc6d8d4eb43ff4f8d7e4c5308f100c32477
2020-02-19 20:08:44 +00:00
Maciej Żenczykowski
cd994cd637 Remove bpfloader dependency on netd's ebpf programs.
This is backwards.  netd should require them,
and they should require bpfloader, not the other way round.

Test: build, atest, ls -lZ /sys/fs/bpf /system/etc/bpf still shows all maps/progs
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iecd95cb69eaad97979af163e63489309826546f6
2020-02-19 10:31:54 -08:00
Automerger Merge Worker
7c6292251f Merge "Pull AID_* constants from shared location." am: 2cd4d70323 am: 421215941d
Change-Id: I1a50d52bf166ff4241f3b49b0780533e8e3039e4
2020-02-19 11:51:27 +00:00
Automerger Merge Worker
421215941d Merge "Pull AID_* constants from shared location." am: 2cd4d70323
Change-Id: I5707a13ce679451d67e67fd14f618530e2df3bcc
2020-02-19 11:35:10 +00:00
Maciej Żenczykowski
2cd4d70323 Merge "Pull AID_* constants from shared location." 2020-02-19 11:16:09 +00:00
Automerger Merge Worker
eee9ae5833 Merge "bpfloader: add dependency on time_in_state.o" am: 5db47e62c4 am: 4d40dee8f7
Change-Id: Iecf8a1d96f648befdc7868fbec71ddd60c4d75e8
2020-02-19 02:52:51 +00:00
Automerger Merge Worker
4d40dee8f7 Merge "bpfloader: add dependency on time_in_state.o" am: 5db47e62c4
Change-Id: I30b702c63684801471bb520c43234315ad007dcc
2020-02-19 02:34:08 +00:00
Connor O'Brien
5db47e62c4 Merge "bpfloader: add dependency on time_in_state.o" 2020-02-19 02:24:31 +00:00
Automerger Merge Worker
9b1edd2bfd add DEFINE_BPF_MAP_GWO macro for group write-only maps am: 62a4dddbba am: b28177909e
Change-Id: I058fb3396900c9ff913198075f30eb29e9794ef1
2020-02-19 00:53:12 +00:00
Automerger Merge Worker
b28177909e add DEFINE_BPF_MAP_GWO macro for group write-only maps am: 62a4dddbba
Change-Id: Iaa65dea4e465b1502586dada6a5ad10be3021b6d
2020-02-19 00:32:12 +00:00
Connor O'Brien
8fa2949910 bpfloader: add dependency on time_in_state.o
Include time_in_state.o in device builds, causing time in state
programs & maps to be loaded.

Bug: 138317993
Test: make bpfloader; check that time_in_state.o is built
Change-Id: I4849bda645d7a02e3f889068987a79ce3f78d138
Signed-off-by: Connor O'Brien <connoro@google.com>
2020-02-18 16:08:28 -08:00
Maciej Żenczykowski
56bf76bbab Pull AID_* constants from shared location.
Test: build, atest
Bug: 149434314
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iadfc7fbbfcb561e7cfafaa5806939c9f69f43d59
2020-02-18 15:21:35 -08:00
Maciej Żenczykowski
62a4dddbba 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
2020-02-18 14:30:39 -08:00
Maciej Żenczykowski
4793eb581f add more precise bpf levels am: 8a09a5ad1c am: ac44c08361
Change-Id: I73d631293028cc3a8149b0f055e38e315f1f1e89
2020-02-18 06:40:50 +00:00
Maciej Żenczykowski
ac44c08361 add more precise bpf levels am: 8a09a5ad1c
Change-Id: I1d79648c8358e58513265dc9eb5e117c0f2748d0
2020-02-18 06:29:26 +00:00
Maciej Żenczykowski
8a09a5ad1c add more precise bpf levels
This is to allow fixing a broken OffloadUtils netd test, but this will
also be useful for future support to make programs per kernel version.

We make the string versions of the enum more readable, because there
is exactly one user:

adb shell dumpsys netd | egrep -i bpf
  BPF module status: enabled
  BPF support level: Extended [4.14]
  ...

Test: build, atest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I843bd7355703a78acc8343ca7f647ce9366927eb
2020-02-18 04:46:58 +00:00
Connor O'Brien
9471823d57 bpfloader: add option to set owner & group for pinned programs am: 3278a1634b am: e173722fc7
Change-Id: Idf9bf79435407020dcf787bc0fda4ec8eb6587d2
2020-02-15 08:01:28 +00:00
Connor O'Brien
e173722fc7 bpfloader: add option to set owner & group for pinned programs am: 3278a1634b
Change-Id: I9e1ca34e2997d3ef6166a4bbed32abb9ca59c5fa
2020-02-15 07:48:38 +00:00
Maciej Żenczykowski
cd5d770866 add bpf_map_def support for setting uid/gid/mode am: 83f2977da8 am: 2c67e65ea2
Change-Id: Ib2aac11b1a1226e5b8627768f07f1b774b06656b
2020-02-15 03:31:37 +00:00
Maciej Żenczykowski
2c67e65ea2 add bpf_map_def support for setting uid/gid/mode am: 83f2977da8
Change-Id: Ie8cd434f246e543a3d25ee9a6cb5325bd192dd68
2020-02-15 03:17:34 +00:00
Maciej Żenczykowski
75478c62e8 bpfloader - add AID_* constants to bpf_map_def.h am: 6f87896bdf am: 3413718218
Change-Id: I02b158b7808477989641d62a458879d2bb37ff68
2020-02-15 02:03:34 +00:00
Maciej Żenczykowski
3413718218 bpfloader - add AID_* constants to bpf_map_def.h am: 6f87896bdf
Change-Id: I66d3d5d208d7e090af4f80421ed66169ba6b0d70
2020-02-15 01:43:57 +00:00
Maciej Żenczykowski
675dc988df grant bpfloader CAP_CHOWN am: 669f7388df am: 0a4b03294a
Change-Id: Ie73ea4c4a04a47529438d84fa357316357fe521f
2020-02-14 23:58:21 +00:00
Maciej Żenczykowski
0a4b03294a grant bpfloader CAP_CHOWN am: 669f7388df
Change-Id: If7a85f1e93a08d3324988ffce1e0bd91356a15f7
2020-02-14 23:46:27 +00:00
Connor O'Brien
3278a1634b 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>
2020-02-14 23:28:44 +00:00
Maciej Żenczykowski
83f2977da8 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
2020-02-14 23:28:26 +00:00
Maciej Żenczykowski
6f87896bdf 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
2020-02-14 23:27:45 +00:00
Maciej Żenczykowski
669f7388df grant bpfloader CAP_CHOWN
so that it can change the uid/gid of pinned bpf progs and maps

Test: build, atest
Bug: 149434314
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id23f9caaddf620d4e99d970523f0a9768826e0d7
2020-02-13 13:08:40 -08:00
Automerger Merge Worker
d0e7971864 BpfUtils.h - add SKIP_IF_EXTENDED_BPF_NOT_SUPPORTED am: 672b0e7aae am: 47a3943182
Change-Id: I5504319fe262139ce1d1af0050542a710779d031
2020-02-13 07:53:48 +00:00
Automerger Merge Worker
47a3943182 BpfUtils.h - add SKIP_IF_EXTENDED_BPF_NOT_SUPPORTED am: 672b0e7aae
Change-Id: Icf8fa12e77ba4b754fed747ab6a013f535e26f4c
2020-02-13 07:35:20 +00:00
Maciej Żenczykowski
672b0e7aae BpfUtils.h - add SKIP_IF_EXTENDED_BPF_NOT_SUPPORTED
(being moved from //system/netd/tests/bpf_base_test.cpp)

Test: build, atest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7a38eff6d86a1bcd6dde193fd360d198bd57a900
2020-02-12 04:15:29 -08:00
Automerger Merge Worker
e7998473bf improve logging in case of bpf load failure am: 524deefc88 am: 292f01efa9
Change-Id: I8e1cd2e5bd5ee954a86043e2d5386910e728fddc
2020-02-12 05:26:45 +00:00
Automerger Merge Worker
292f01efa9 improve logging in case of bpf load failure am: 524deefc88
Change-Id: I75610e9c78c47269fd086cb21fbf4669be7b07a3
2020-02-12 05:11:38 +00:00
Maciej Żenczykowski
524deefc88 improve logging in case of bpf load failure
(we don't want to truncate this output, since it can be very useful
for debugging failures)

Test: builds, more useful ebpf load failure logs
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I817853f33b7f59296a041fb0d26ca3ae502b29da
2020-02-11 19:12:34 -08:00
Automerger Merge Worker
6311492750 'static inline' -> 'inline' am: 06caf87004 am: 237f079a9b
Change-Id: I4853b4bce8459a77f6d83058514744d12bc5c3ff
2020-02-12 02:59:12 +00:00
Automerger Merge Worker
237f079a9b 'static inline' -> 'inline' am: 06caf87004
Change-Id: Ie1d004105dc28b6b8df4138e158a747c7a29eb47
2020-02-12 02:39:49 +00:00
Automerger Merge Worker
4e84598d75 introduce isBpfSupported() helper am: c3a640db94 am: 7b34dd654f
Change-Id: Ic6581b0374646a090c2b98382842ef235258997d
2020-02-12 01:22:12 +00:00
Automerger Merge Worker
7b34dd654f introduce isBpfSupported() helper am: c3a640db94
Change-Id: Iecb173444c2c2c48759221c212c6b50980ed8a0c
2020-02-12 01:10:17 +00:00
Maciej Żenczykowski
06caf87004 'static inline' -> 'inline'
Per Bernie: "in C++, inline implies internal linkage, you can drop static"

Test: build, atest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I139af1d826d4982a1480fbee433fd9a743509786
2020-02-11 16:43:15 -08:00
Maciej Żenczykowski
c3a640db94 introduce isBpfSupported() helper
Test: build, atest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9e2a7e049746ad193eea01e7c9d6786d27728c72
2020-02-11 15:05:27 -08:00
Automerger Merge Worker
892c704118 fix getBpfSupportLevel() cache wrt. multi-threading am: 8bd5f39348 am: aa9d077681
Change-Id: Ie9c655df41322f6931a832fdedc1677c51895d5a
2020-02-11 22:52:22 +00:00
Automerger Merge Worker
aa9d077681 fix getBpfSupportLevel() cache wrt. multi-threading am: 8bd5f39348
Change-Id: I4d1e25d537e9a4d70a64e09bc0027b08aa0f7f00
2020-02-11 22:36:40 +00:00
Automerger Merge Worker
85972bca64 Merge "make getBpfSupportLevel() cached" am: 61588e0e64 am: 87d8cc7d76
Change-Id: I92be5d2a7a3041e4819c1ac3a2153249605acaa5
2020-02-11 19:31:11 +00:00
Automerger Merge Worker
87d8cc7d76 Merge "make getBpfSupportLevel() cached" am: 61588e0e64
Change-Id: I0dc4bcfd15a8938302c1e98ad5ce72e1c25a96ab
2020-02-11 19:23:39 +00:00