diff options
author | Maciej Żenczykowski <maze@google.com> | 2020-01-27 03:11:51 -0800 |
---|---|---|
committer | Maciej Żenczykowski <maze@google.com> | 2020-02-14 23:28:26 +0000 |
commit | 83f2977da8b9a51ea665acdc6e0e336aa3781604 (patch) | |
tree | 096062baab0b60e4f5b0556d91edd1961fcef30c /progs | |
parent | 6f87896bdf30bcbca4616b3afa8e328d939d0c97 (diff) | |
download | bpf-83f2977da8b9a51ea665acdc6e0e336aa3781604.tar.gz |
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
Diffstat (limited to 'progs')
-rw-r--r-- | progs/include/bpf_helpers.h | 29 | ||||
-rw-r--r-- | progs/include/bpf_map_def.h | 4 |
2 files changed, 23 insertions, 10 deletions
diff --git a/progs/include/bpf_helpers.h b/progs/include/bpf_helpers.h index 825947f..ac08649 100644 --- a/progs/include/bpf_helpers.h +++ b/progs/include/bpf_helpers.h @@ -53,16 +53,16 @@ static int (*bpf_map_delete_elem_unsafe)(const void* map, const void* key) = (void*)BPF_FUNC_map_delete_elem; /* type safe macro to declare a map and related accessor functions */ -#define DEFINE_BPF_MAP_NO_ACCESSORS(the_map, TYPE, TypeOfKey, TypeOfValue, num_entries) \ - const struct bpf_map_def SEC("maps") the_map = { \ - .type = BPF_MAP_TYPE_##TYPE, \ - .key_size = sizeof(TypeOfKey), \ - .value_size = sizeof(TypeOfValue), \ - .max_entries = (num_entries), \ - }; - -#define DEFINE_BPF_MAP(the_map, TYPE, TypeOfKey, TypeOfValue, num_entries) \ - DEFINE_BPF_MAP_NO_ACCESSORS(the_map, TYPE, TypeOfKey, TypeOfValue, num_entries) \ +#define DEFINE_BPF_MAP_UGM(the_map, TYPE, TypeOfKey, TypeOfValue, num_entries, usr, grp, md) \ + const struct bpf_map_def SEC("maps") the_map = { \ + .type = BPF_MAP_TYPE_##TYPE, \ + .key_size = sizeof(TypeOfKey), \ + .value_size = sizeof(TypeOfValue), \ + .max_entries = (num_entries), \ + .uid = (usr), \ + .gid = (grp), \ + .mode = (md), \ + }; \ \ static inline __always_inline __unused TypeOfValue* bpf_##the_map##_lookup_elem( \ const TypeOfKey* k) { \ @@ -78,6 +78,15 @@ static int (*bpf_map_delete_elem_unsafe)(const void* map, return bpf_map_delete_elem_unsafe(&the_map, k); \ }; +#define DEFINE_BPF_MAP(the_map, TYPE, TypeOfKey, TypeOfValue, num_entries) \ + DEFINE_BPF_MAP_UGM(the_map, TYPE, TypeOfKey, TypeOfValue, num_entries, AID_ROOT, AID_ROOT, 0600) + +#define DEFINE_BPF_MAP_GRO(the_map, TYPE, TypeOfKey, TypeOfValue, num_entries, gid) \ + DEFINE_BPF_MAP_UGM(the_map, TYPE, TypeOfKey, TypeOfValue, num_entries, AID_ROOT, gid, 0640) + +#define DEFINE_BPF_MAP_GRW(the_map, TYPE, TypeOfKey, TypeOfValue, num_entries, gid) \ + DEFINE_BPF_MAP_UGM(the_map, TYPE, TypeOfKey, TypeOfValue, num_entries, AID_ROOT, gid, 0660) + static int (*bpf_probe_read)(void* dst, int size, void* unsafe_ptr) = (void*) BPF_FUNC_probe_read; static int (*bpf_probe_read_str)(void* dst, int size, void* unsafe_ptr) = (void*) BPF_FUNC_probe_read_str; static unsigned long long (*bpf_ktime_get_ns)(void) = (void*) BPF_FUNC_ktime_get_ns; diff --git a/progs/include/bpf_map_def.h b/progs/include/bpf_map_def.h index 89a96d4..b233dc9 100644 --- a/progs/include/bpf_map_def.h +++ b/progs/include/bpf_map_def.h @@ -62,4 +62,8 @@ struct bpf_map_def { // The following are not supported by the Android bpfloader: // unsigned int inner_map_idx; // unsigned int numa_node; + + unsigned int uid; // uid_t + unsigned int gid; // gid_t + unsigned int mode; // mode_t }; |