Commit graph

1985 commits

Author SHA1 Message Date
Ken Chen
898537a0c6 Rename bpf_load_tp_prog.o and bpf_load_tp_prog_btf.o am: 8693c789d3 am: 23fb1a6884 am: b11c90ffce am: 0cf06c23d7
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2146828

Change-Id: Ic15602e2c451355d66960847da460d7b01652c36
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-12 14:15:51 +00:00
Ken Chen
0cf06c23d7 Rename bpf_load_tp_prog.o and bpf_load_tp_prog_btf.o am: 8693c789d3 am: 23fb1a6884 am: b11c90ffce
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2146828

Change-Id: I7f1682b366baa8df6445fc89bb34fd5ed4b8bc18
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-12 13:59:22 +00:00
Ken Chen
b11c90ffce Rename bpf_load_tp_prog.o and bpf_load_tp_prog_btf.o am: 8693c789d3 am: 23fb1a6884
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2146828

Change-Id: I23e354c3bb373e6f3edda45363e2ecc826203148
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-12 13:37:37 +00:00
Ken Chen
23fb1a6884 Rename bpf_load_tp_prog.o and bpf_load_tp_prog_btf.o am: 8693c789d3
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2146828

Change-Id: I2dfd985fed650213d9ecc002bfa6385c8f2f7cd0
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-12 13:19:57 +00:00
Xin Li
3e36c00b18 DO NOT MERGE - Merge TP1A.220624.013
Merged-In: I553e90e0414453f8f3aaca8cf05d5decc8b911a2
Change-Id: I86969f4b387004f64713035423692fd2c9df3aaf
2022-07-11 21:47:46 -07:00
Ken Chen
498d20b706 Rename time_in_state.o to timeInState.o
Underscore character may cause bpf prog/map naming collision. For
example, x.o with map y_z and x_y.o with map z both result in x_y_z
prog/map name, which should be prevented during compile-time.

aosp/2147825 will prohibit underscore character in bpf source name
(source name derives the obj name). Existing bpf modules with underscore
characters in source name need to be updated accordingly.

Bug: 236706995
Test: adb root; adb shell ls -l /sys/fs/bpf/ | grep timeInState
Change-Id: Ia4eefd8b7debed2c81e194052488e15df72cab69
2022-07-10 19:10:36 +08:00
Ken Chen
8693c789d3 Rename bpf_load_tp_prog.o and bpf_load_tp_prog_btf.o
Underscore character may cause bpf prog/map naming collision. For
example, x.o with map y_z and x_y.o with map z both result in x_y_z
prog/map name, which should be prevented during compile-time.

aosp/2147825 will prohibit underscore character in bpf source name
(source name derives the obj name). Existing bpf modules with underscore
characters in source name need to be updated accordingly.

Bug: 236706995
Test: atest libbpf_load_test
Change-Id: I037ccfedc4d2e48688ee47f575c73998ce1c2c4b
2022-07-10 18:31:18 +08:00
Treehugger Robot
9bc91472c6 Merge "BpfLoader v0.25 - add support for obj@ver.o" am: d6c6835f27 am: 032c305dd8 am: c8f29c0862 am: d932842d60 am: 93fd05d4bb
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2147468

Change-Id: I06a86330d30e7d80485d8f2e50ceb9f326ab82f2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-07 21:03:28 +00:00
Treehugger Robot
93fd05d4bb Merge "BpfLoader v0.25 - add support for obj@ver.o" am: d6c6835f27 am: 032c305dd8 am: c8f29c0862 am: d932842d60
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2147468

Change-Id: I8db2b240f1b7dc0c24523ffefd97fe0393f12eac
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-07 20:47:20 +00:00
Treehugger Robot
d932842d60 Merge "BpfLoader v0.25 - add support for obj@ver.o" am: d6c6835f27 am: 032c305dd8 am: c8f29c0862
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2147468

Change-Id: I71ea130b80957490e4ceb23aa5f80a6b9976d88f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-07 20:25:07 +00:00
Treehugger Robot
c8f29c0862 Merge "BpfLoader v0.25 - add support for obj@ver.o" am: d6c6835f27 am: 032c305dd8
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2147468

Change-Id: Id9d38b9ed2b5709182262873c914b9268316488e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-07 20:08:25 +00:00
Treehugger Robot
032c305dd8 Merge "BpfLoader v0.25 - add support for obj@ver.o" am: d6c6835f27
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2147468

Change-Id: I7ad3b64790a61d163af7e36bec870ec752eb45e1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-07 19:43:17 +00:00
Treehugger Robot
d6c6835f27 Merge "BpfLoader v0.25 - add support for obj@ver.o" 2022-07-07 19:29:22 +00:00
Maciej Żenczykowski
21869ef935 BpfLoader v0.25 - add support for obj@ver.o
This allows for 2 different versions of obj.o to be
shipped simultaneously (via mainline module),
with different bpfloader version limitations.

For example a obj.o for bpfloader < 0.25 and a
obj@25.o for bpfloader 0.25+.  These can provide
for different implementations of maps/programs,
while still being pinned into the same ultimate
destination in /sys/fs/bpf/.../{map,prog}_obj_...
so as to not require special selection of appropriate
program/map path names in higher level code
(at least for common functionality).

When using this functionality one does have to be
careful to not end up with unintentional duplication
(ie. an obj@1.o and obj@2.o that both load on bpfloader
version X), and to make sure that the defined
bpf maps and programs with identical names
are also sufficiently identical in behaviour.

In practice it is likely that all versions of obj@ver.o
will be built from the same source code, with compilation
controlled by appropriate preprocessor conditional macros,
to hide certain parts of obj.c while building the version
for older bpfloader...

However, exactly how to use this is ultimately
left up to the future...
Multiple viable mechanisms exist:

(a) each obj@ver.o is standalone, only one should be loaded,
    bpfloader min/max version annotations would be used
    to guarantee this, making sure that programs/maps that
    exist in multiple versions of obj.o should have matching
    types and behaviours, but nothing guarantees this
    (although key/value size checks will certainly help)
(b) obj.o is baseline and always loaded,
    while obj@25.o is an extension with extra maps/programs
    and is loaded on only newer bpfloaders,
    it may have duplicate defines of shared maps
    (likely via #include of some shared header file)
    if some of the extra programs also need some of
    the data from maps from the 'older' obj.o
(c) variously complex combinations of (a) and (b) are also possible

Bug: 218408035
Test: TreeHugger, manually with offload@1.o in p/m/C
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ib60d07b18fd6617d456c2c469f8e8ed166aadffd
2022-07-07 18:00:18 +00:00
Ken Chen
3f9649a64b Remove redundant line feed in log am: e1b518ce76 am: 1e406370fd am: 62834a5567 am: b50732969c am: 5bdd91405d
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2146822

Change-Id: I7fde8b9203cf86f740b858dcfb232ae8db7efd1c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-06 21:36:02 +00:00
Ken Chen
5bdd91405d Remove redundant line feed in log am: e1b518ce76 am: 1e406370fd am: 62834a5567 am: b50732969c
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2146822

Change-Id: Ie22c9f9a4450cbb910949536cb3fba55f3bc632d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-06 21:17:25 +00:00
Ken Chen
b50732969c Remove redundant line feed in log am: e1b518ce76 am: 1e406370fd am: 62834a5567
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2146822

Change-Id: I27f02e59086652c6544ba8aaa5ed4b3920b85be0
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-06 20:53:52 +00:00
Ken Chen
62834a5567 Remove redundant line feed in log am: e1b518ce76 am: 1e406370fd
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2146822

Change-Id: I9f36491977d185df7f07405ed71fe4a24ce8ffca
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-06 20:27:06 +00:00
Ken Chen
1e406370fd Remove redundant line feed in log am: e1b518ce76
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2146822

Change-Id: Id3058b03562080649eaef0c0e9ec2be11b52fd12
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-06 20:07:41 +00:00
Ken Chen
e1b518ce76 Remove redundant line feed in log
This can save 568 lines of trace at startup.

Before:
05-19 13:50:09.053 ... 950 LibBpfLoader: applying relo to instruction...
05-19 13:50:09.053 ... 950 LibBpfLoader:
05-19 13:50:09.053 ... 950 LibBpfLoader: applying relo to instruction...
05-19 13:50:09.053 ... 950 LibBpfLoader:
05-19 13:50:09.053 ... 950 LibBpfLoader: applying relo to instruction...
05-19 13:50:09.053 ... 950 LibBpfLoader:

After:
05-19 13:53:02.263 ... 975 LibBpfLoader: applying relo to instruction...
05-19 13:53:02.263 ... 975 LibBpfLoader: applying relo to instruction...
05-19 13:53:02.263 ... 975 LibBpfLoader: applying relo to instruction...

Test: adb reboot; adb logcat | grep LibBpfLoader
Change-Id: I2bff44ebfa5ba3af6ef41def1967ab1ae44852f7
2022-07-06 17:09:47 +00:00
Maciej Żenczykowski
88199acf27 bpfloader: left justify logging of pin_subdir and selinux_context am: 996684608c am: 49f224d178 am: e202a55aba am: f297f7baf4 am: bbf97ee600
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143202

Change-Id: I6c05d57e04fc2ad530293c31a19464af4a2b7b44
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-04 00:11:48 +00:00
Maciej Żenczykowski
dfb927eae1 bpfloader: provide a way to fail loading a bpf .o due to old version am: b57290a597 am: 19fd0aaedc am: c6262ef7f6 am: 1772880d94 am: a3bb0990f6
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143200

Change-Id: I97ba0ff5aa4b02576c8dd7b0f2b4b8e30d10038e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-04 00:11:36 +00:00
Maciej Żenczykowski
7374542c55 grant bpfloader explicit membership in some groups am: bbf5ee3971 am: 9ecb84a4c7 am: 519d825150 am: eb01503849 am: c0e76f7ddf
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143199

Change-Id: I6cd3cbf326688dd3abc14478e8169cab1fb393e3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-04 00:11:35 +00:00
Maciej Żenczykowski
bbf97ee600 bpfloader: left justify logging of pin_subdir and selinux_context am: 996684608c am: 49f224d178 am: e202a55aba am: f297f7baf4
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143202

Change-Id: I0ca2d71c165c03daedfdc03f749597118469837e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-03 23:55:13 +00:00
Maciej Żenczykowski
a3bb0990f6 bpfloader: provide a way to fail loading a bpf .o due to old version am: b57290a597 am: 19fd0aaedc am: c6262ef7f6 am: 1772880d94
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143200

Change-Id: I30583a3f934183cd7554af16aaa205c44bd5ba8d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-03 23:55:03 +00:00
Maciej Żenczykowski
c0e76f7ddf grant bpfloader explicit membership in some groups am: bbf5ee3971 am: 9ecb84a4c7 am: 519d825150 am: eb01503849
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143199

Change-Id: I8b6b4c4e550b999bba74ca324966bf56d8609531
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-03 23:55:02 +00:00
Maciej Żenczykowski
f297f7baf4 bpfloader: left justify logging of pin_subdir and selinux_context am: 996684608c am: 49f224d178 am: e202a55aba
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143202

Change-Id: I0bfa50d67f44a5604cdd9b2d01d271f2dff46ced
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-03 23:37:19 +00:00
Maciej Żenczykowski
1772880d94 bpfloader: provide a way to fail loading a bpf .o due to old version am: b57290a597 am: 19fd0aaedc am: c6262ef7f6
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143200

Change-Id: I4301b9254c6dd48bc90a4073700d5f7342666ca5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-03 23:37:08 +00:00
Maciej Żenczykowski
eb01503849 grant bpfloader explicit membership in some groups am: bbf5ee3971 am: 9ecb84a4c7 am: 519d825150
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143199

Change-Id: I4ce487aefc25622c8d1b136a42875aa72976401c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-03 23:37:07 +00:00
Maciej Żenczykowski
e202a55aba bpfloader: left justify logging of pin_subdir and selinux_context am: 996684608c am: 49f224d178
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143202

Change-Id: Id1ccdae5796da0185bd038c955fefbd4c84dd0da
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-03 23:14:03 +00:00
Maciej Żenczykowski
c6262ef7f6 bpfloader: provide a way to fail loading a bpf .o due to old version am: b57290a597 am: 19fd0aaedc
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143200

Change-Id: I6d3b8592d64629373f425993adcf085fca768a9e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-03 23:13:53 +00:00
Maciej Żenczykowski
519d825150 grant bpfloader explicit membership in some groups am: bbf5ee3971 am: 9ecb84a4c7
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143199

Change-Id: I6093374c55a0a09b1f022ecd47b0399edf829492
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-03 23:13:50 +00:00
Maciej Żenczykowski
49f224d178 bpfloader: left justify logging of pin_subdir and selinux_context am: 996684608c
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143202

Change-Id: I73b84609945b935c65afde42c8529a52f852622a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-03 22:53:41 +00:00
Maciej Żenczykowski
19fd0aaedc bpfloader: provide a way to fail loading a bpf .o due to old version am: b57290a597
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143200

Change-Id: I243ad0e4943dfcfab5065a8d3aafa8df4a3f31bb
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-03 22:53:33 +00:00
Maciej Żenczykowski
9ecb84a4c7 grant bpfloader explicit membership in some groups am: bbf5ee3971
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143199

Change-Id: I3cb54fefac11fe3a24cbdc41a0ea864197982463
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-03 22:53:31 +00:00
Maciej Żenczykowski
996684608c bpfloader: left justify logging of pin_subdir and selinux_context
(this more closely matches how this is stored in the 32 char field,
 and is thus simply less confusing)

Before:
  I LibBpfLoader: map configuration_map selinux_context [            fs_bpf_netd_readonly] -> 5 -> 'fs_bpf_netd_readonly' (netd_readonly/)
After:
  I LibBpfLoader: map configuration_map selinux_context [fs_bpf_netd_readonly            ] -> 5 -> 'fs_bpf_netd_readonly' (netd_readonly/)

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I734f21b7bf562a411fcb2b21fe5bb20fb7004ec9
2022-07-03 22:30:58 +00:00
Maciej Żenczykowski
b57290a597 bpfloader: provide a way to fail loading a bpf .o due to old version
we currently have a way to entirely ignore a bpf .o file on older
bpfloaders, however sometimes (especially during development) we
don't want the file to be ignored (because it is required for correct
system operation) but we already know at build time that it is incompatible
due to some missing bpfloader functionality.

While in such a situation stuff will likely fail anyway (either
bpfloader will fail due to missing privs or maps/programs won't
be created and netd updatable library will fail, or something else...),
this happens *much* later and is actually much harder to debug.

This way the failure is early, and the error message is clear.

This will make it easier for us to prevent such broken setups
from ever making it out to devices, as - for a critical program
- the resulting bpfloader boot time failure will trigger a mainline
module rollback.

While developing further isolation changes to tethering apex bpf
programs I've run into cases where I've wanted to make changes
that requires bpfloader >= X to work correctly.  This will help
make such changes safely in the future.

Bug: 218408035
Test: TreeHugger, manual testing
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic11b48312dfe5960b787e1786b690773a41a4d18
2022-07-02 23:04:51 +00:00
Maciej Żenczykowski
bbf5ee3971 grant bpfloader explicit membership in some groups
(this is instead of relying on the CAP_CHOWN capability it has)

The goal is to allow bpfloader to open maps/programs it creates,
so that it can reuse them.  By virtue of CAP_CHOWN it can create,
pin, then give away ownership, and no longer be able to bpf_obj_get()
the pinned map or program (to reuse it at a later time).

This could be considered a partial (more targetted) workaround
for the lack of bpfloader CAP_DAC_OVERRIDE (or CAP_DAC_READ_SEARCH).
But for obvious reasons jeffv@ doesn't really want to grant that.

In some sense this doesn't actually really grant any privs on a writeable
filesystem, as CHOWN already allows stealing ownership...

However explicit membership is much easier to reason about,
and does not require playing:
- stat (to get current uid/gid/mode)
- chown (set uid to root, ie. self -- works due to CAP_CHOWN)
- chmod (grant user read if missing)
- bpf_obj_get (this now succeeds -- does not require capabilities)
- chmod (restore mode)
- chown (restore uid -- works due to CAP_CHOWN)
games in order to open pinned bpf maps/programs we'd normally be unable
to open due to unix uid/gid/mode restrictions.

Yes, I've verified the above 'magic' actually works with current privs,
provided we grant the missing 'getattr' selinux priv to allow the stat() call.
(obviously without it we can still gain access, we just can't undo things)

Currently /sys/fs/bpf maps and program ownership on a tip-of-tree T device looks like:

$ adb shell getprop ro.build.fingerprint
google/oriole/oriole:13/TP1A.220624.007/8785063:userdebug/dev-keys

$ adb shell ls -l /sys/fs/bpf/* | egrep '^-' | cut -d' ' -f3-4 | sort | uniq -c

count uid  gid            examples
    5 root graphics       platform:          gpu_mem.o & gpu_work.o
    5 root net_admin      tethering apex T+: netd.o skfilter_..._xtbpf & schedact_ingress_account programs
   10 root net_bw_acct    tethering apex T+: netd.o maps
   24 root network_stack  tethering apex S+: offload.o & test.o
    1 root root           tethering apex T+: netd.o cgroupsock_inet_create program
   38 root system         platform & tethering apex T+: time_in_state.o, block.o, clatd.o, dscp_policy.o, netd.o cgroupskb_(e|in)gress_stats

And additionally due to the utter lack of a 'groups' line in bpfloader.rc,
the default bpfloader gid is of course 'root'.

This suggests we should use:
  groups root graphics network_stack net_admin net_bw_acct system

(but only really mainline updatable stuff matters, so we could limit
 this to just networking and strip out 'graphics'...)

A glance through:
  system/core/libcutils/include/private/android_filesystem_config.h

Finds the following groups which might be of interest to bpfloader & mainline networking:
* root
* system
* graphics

  dhcp
  vpn
  mdnsr
  clat
  dns
  dns_tether
* network_stack

  inet
  net_raw
* net_admin
  net_bw_stats
* net_bw_acct

[stars mark the one's we've already identified previously]

Networking mainline code runs in 3 processes: netd, system_server and network_stack.

Based on looking at a live oriole device, these processes have the following
uid/gid/groups/capabilities:

netd - uid:0[root] gid:0[root] + 3005[net_admin]
Cap: 00000000000074ef=cap_chown,cap_dac_override,cap_dac_read_search,cap_fowner,cap_kill,cap_setgid,cap_setuid,cap_net_bind_service,cap_net_admin,cap_net_raw,cap_ipc_lock

networkstack.process - uid:1073[network_stack] gid:1073[network_stack] + 1073[network_stack]
3002[net_bt] 3003[inet] 3004[net_raw] 3005[net_admin] 3006[net_bw_stats] 3007[net_bw_acct] 9997[everybody]
Cap: 0000000000003c00=cap_net_bind_service,cap_net_broadcast,cap_net_admin,cap_net_raw

system_server - uid:1000[system] gid:1000[system] + 1001[radio] 1002[bluetooth] 1003[graphics]
1004[input] 1005[audio] 1006[camera] 1007[log] 1008[compass] 1009[mount] 1010[wifi]
1018[usb] 1021[gps] 1023[media_rw] 1024[mtp] 1032[package_info] 1065[reserved_disk]
3001[net_bt_admin] 3002[net_bt] 3003[inet] 3005[net_admin] 3006[net_bt_stats] 3007[net_bw_acct]
3009[readproc] 3010[wakeloc] 3011[uhid] 3012[readtracefs]
Cap: 0000001806897c20=cap_kill,cap_net_bind_service,cap_net_broadcast,cap_net_admin,cap_net_raw,cap_ipc_lock,cap_sys_module,cap_sys_ptrace,cap_sys_nice,cap_sys_time,cap_sys_tty_config,cap_wake_alarm,cap_block_suspend

Since netd has DAC_OVERRIDE, it really doesn't matter from a group analysis perspective
(side note: it probably should have a lot more groups than it actually does...)
Either way, both *root & *net_admin are already in the above list.

For the network stack process the obvious groups are:
  *network_stack, net_raw, *net_admin, net_bw_stats, *net_bw_acct
which means we should add:
  net_raw, net_bw_stats
to the above list.

(I'm assuming 'inet' & 'everybody' are too generic groups to be of use for bpf,
 and that we don't [yet] care about bluetooth (net_bt) being able to use bpf directly)

For the system server the choice is harder, but I'd tend to pick:
  *system, *graphics, *net_admin, *net_bw_acct

(Again ignoring non-networking stuff, and assuming radio/bluetooth/wifi bpf
  use will come at some later point in time.)

This gives us decent coverage of the 3 processes (and combinations there-of):
  netd process                         -> group root
  network stack process                -> group network_stack
  system server process                -> group system
  both network stack and system server -> group net_bw_acct
Note that due to DAC_OVERRIDE netd always has unix access no matter what,
and needs to be limited via selinux contexts instead.

Additionally 'net_admin' is used for xt_bpf iptables programs due to need
for netutils_wrappers support and it is also usable by all 3 processes.

This means we can fully explain all groups that currently show up as in use.
Adding net_raw & net_bw_stats is possibly not needed, but also won't hurt,
and might be useful in the future.

We could also argue that we should add:
  dhcp, vpn, mdnsr, clat, dns, dns_tether & inet

But since none of our mainline code running processes are currently
members of those groups (besides netd due to DAC_OVERRIDE), there doesn't
seem to be much benefit (this can't be changed with mainline pushes).

I assume new stuff which would need these groups will actually only be loaded
on U+ bpfloader, which will have a less hacky solution for this problem anyway.

Note: on U+ bpfloader we should probably fix this by simply caching
all bpf map/prog filedescriptors in a path->fd hashmap, and thus
avoid the need to ever reopen anything.  This is a far more invasive change,
but once done we should be able to revert this change.

For safety we'll also want to make sure we abort() if we detect cases
that cannot be safely handled by S bpfloader, an example would be
maps with uid != root in tethering location.

Bug: 218408035
Bug: 237716689
Test: TreeHugger, manual testing
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I742868b1a6819547fcd7a3573946a2fc479a21a5
2022-07-02 23:04:41 +00:00
Maciej Żenczykowski
6b9ed3a8d1 limit types of bpf programs that platform and tethering apex can load am: ae58e7e4a7 am: eb6c2ece0b am: d00ef559b2 am: b93ad707d2 am: e9584c67b1
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143735

Change-Id: I57fd4ca56fa7c33ada60caf50fea56b6d03cf4e6
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-01 23:52:18 +00:00
Maciej Żenczykowski
e9584c67b1 limit types of bpf programs that platform and tethering apex can load am: ae58e7e4a7 am: eb6c2ece0b am: d00ef559b2 am: b93ad707d2
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143735

Change-Id: I44611687c279720b75b9d6e198d78b822d6e5b56
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-01 23:32:54 +00:00
Maciej Żenczykowski
b93ad707d2 limit types of bpf programs that platform and tethering apex can load am: ae58e7e4a7 am: eb6c2ece0b am: d00ef559b2
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143735

Change-Id: Ia124d5f0aedc730b1bc2889c504223cc2f4ea593
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-01 23:16:30 +00:00
Maciej Żenczykowski
d00ef559b2 limit types of bpf programs that platform and tethering apex can load am: ae58e7e4a7 am: eb6c2ece0b
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143735

Change-Id: I96728b8f9fce51bb1021b8f1b772b7e0f3fe21b5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-01 22:58:02 +00:00
Maciej Żenczykowski
eb6c2ece0b limit types of bpf programs that platform and tethering apex can load am: ae58e7e4a7
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143735

Change-Id: I4b28c0d4bc79cea268dc285dc69f6aa2c4d2a175
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-01 22:40:02 +00:00
Maciej Żenczykowski
7726b3ee2c Merge "Perform map chmod *before* chown" am: e867b84dae am: 2c8f2fac61 am: a161c1bf8b am: 5d9e2e4ef0 am: 594ecd3993
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143734

Change-Id: I499480a4edba7526e435d79f519b1cc342d2602c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-01 21:54:43 +00:00
Maciej Żenczykowski
5927bd79ef Merge "use mapRetrieveRO() instead of bpf_obj_get()" am: 81329bd9e9 am: ced7df1d56 am: b0f95435d6 am: 4d02939973 am: fca84de355
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143733

Change-Id: I0b3bb309c5add3f01370181c3dbb06cb81fb7979
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-01 21:52:04 +00:00
Maciej Żenczykowski
594ecd3993 Merge "Perform map chmod *before* chown" am: e867b84dae am: 2c8f2fac61 am: a161c1bf8b am: 5d9e2e4ef0
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143734

Change-Id: I19349f49d54eeb315d2414b6ffa7425253fb79f6
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-01 21:27:28 +00:00
Maciej Żenczykowski
fca84de355 Merge "use mapRetrieveRO() instead of bpf_obj_get()" am: 81329bd9e9 am: ced7df1d56 am: b0f95435d6 am: 4d02939973
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143733

Change-Id: I0863581bf8c51bf91631fc799db9ffee62f685a3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-01 21:25:11 +00:00
Maciej Żenczykowski
cea3ff68b6 add missing logging for bpf_obj_pin operation am: d8259aa1e4 am: febb48d501 am: c1e51cfe15 am: ab5a0ab278 am: 1c1af743fb
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143113

Change-Id: I7e72bfbad59ef79141cfadddfb5b1b286900cead
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-01 21:08:49 +00:00
Maciej Żenczykowski
5d9e2e4ef0 Merge "Perform map chmod *before* chown" am: e867b84dae am: 2c8f2fac61 am: a161c1bf8b
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143734

Change-Id: I7f89b4e9bbf5eef949160791d35515505165e2ad
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-01 21:01:42 +00:00
Maciej Żenczykowski
4d02939973 Merge "use mapRetrieveRO() instead of bpf_obj_get()" am: 81329bd9e9 am: ced7df1d56 am: b0f95435d6
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2143733

Change-Id: Ia36bb839e47bd8ae73a03441efc8b6364edb5983
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-01 21:01:33 +00:00