No description
Find a file
Maciej Żenczykowski eb199dd748 use mapRetrieveRO() instead of bpf_obj_get()
bpf_obj_get(path) is entirely equivalent to mapRetrieveRW(path)

See implementation in frameworks/libs/net common/native/bpf_syscall_wrappers/include/BpfSyscallWrappers.h:

inline int bpfFdGet(const char* pathname, uint32_t flag) {
    return bpf(BPF_OBJ_GET, {
                                    .pathname = ptr_to_u64(pathname),
                                    .file_flags = flag,
                            });
}

inline int mapRetrieve(const char* pathname, uint32_t flag) { return bpfFdGet(pathname, flag); }
inline int mapRetrieveRW(const char* pathname) { return mapRetrieve(pathname, 0); }
inline int mapRetrieveRO(const char* pathname) { return mapRetrieve(pathname, BPF_F_RDONLY); }
inline int mapRetrieveWO(const char* pathname) { return mapRetrieve(pathname, BPF_F_WRONLY); }
inline int retrieveProgram(const char* pathname) { return bpfFdGet(pathname, BPF_F_RDONLY); }

However, this requires selinux file:write access which bpfloader
currently lacks, ie. we would need:

system/sepolicy private/bpfloader.te:
  -allow bpfloader bpffs_type:file { create read rename setattr };
  +allow bpfloader bpffs_type:file { create read rename setattr write };

Switching from mapRetrieveRW() to mapRetrieveRO() eliminates this problem.

BpfLoader itself does not need to write to the maps, while bpf program write
access is controlled by a different bit (it is independent of the r/w access
bits of the file descriptor itself).

Verified by re-opening the maps after pinning them.

Bug: 218408035
Bug: 237716689
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ica7ac8ee48d4a73e5f92dbf47cd441c3bfba38cf
2022-07-01 15:56:21 +00:00
bpfloader bpfloader: support 'shared' maps and per-map/program selinux context 2022-06-21 02:23:09 -07:00
libbpf_android use mapRetrieveRO() instead of bpf_obj_get() 2022-07-01 15:56:21 +00:00
progs Include android_filesystem_config.h in mock_bpf_helpers.h 2022-03-08 17:30:53 -08:00
.clang-format Replace clang-format with symlink. 2019-01-18 14:26:33 -08:00
Android.bp [LSC] Add LOCAL_LICENSE_KINDS to system/bpf 2021-02-05 01:28:19 -08:00
NOTICE Fix the build problem with bpf project 2018-10-16 21:17:12 -07:00
OWNERS Always use OWNERS from master branch. 2021-11-17 10:51:28 -08:00
OWNERS_bpf Always use OWNERS from master branch. 2021-11-17 10:51:28 -08:00
PREUPLOAD.cfg Fix the build problem with bpf project 2018-10-16 21:17:12 -07:00