mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-13 00:00:00 -04:00
BACKPORT: ANDROID: fuse-bpf v1
Bug: 202785178 Test: test_fuse passes on linux, feature works on cuttlefish Signed-off-by: Paul Lawrence <paullawrence@google.com> Signed-off-by: Daniel Rosenberg <drosen@google.com> Change-Id: I987684b799b07391ccde350e98fde7976f5601aa
This commit is contained in:
parent
2e6dc19099
commit
b3fbcd3ca5
16 changed files with 3213 additions and 70 deletions
|
|
@ -36,3 +36,6 @@ obj-$(CONFIG_BPF_SYSCALL) += bpf_struct_ops.o
|
|||
obj-${CONFIG_BPF_LSM} += bpf_lsm.o
|
||||
endif
|
||||
obj-$(CONFIG_BPF_PRELOAD) += preload/
|
||||
ifeq ($(CONFIG_FUSE_BPF),y)
|
||||
obj-$(CONFIG_BPF_SYSCALL) += bpf_fuse.o
|
||||
endif
|
||||
|
|
|
|||
72
kernel/bpf/bpf_fuse.c
Normal file
72
kernel/bpf/bpf_fuse.c
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
// Copyright (c) 2021 Google LLC
|
||||
|
||||
#include <linux/filter.h>
|
||||
#include <linux/fuse.h>
|
||||
|
||||
static const struct bpf_func_proto *
|
||||
fuse_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
|
||||
{
|
||||
switch (func_id) {
|
||||
case BPF_FUNC_trace_printk:
|
||||
return bpf_get_trace_printk_proto();
|
||||
|
||||
case BPF_FUNC_get_current_uid_gid:
|
||||
return &bpf_get_current_uid_gid_proto;
|
||||
|
||||
case BPF_FUNC_get_current_pid_tgid:
|
||||
return &bpf_get_current_pid_tgid_proto;
|
||||
|
||||
case BPF_FUNC_map_lookup_elem:
|
||||
return &bpf_map_lookup_elem_proto;
|
||||
|
||||
case BPF_FUNC_map_update_elem:
|
||||
return &bpf_map_update_elem_proto;
|
||||
|
||||
default:
|
||||
pr_debug("Invalid fuse bpf func %d\n", func_id);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static bool fuse_prog_is_valid_access(int off, int size,
|
||||
enum bpf_access_type type,
|
||||
const struct bpf_prog *prog,
|
||||
struct bpf_insn_access_aux *info)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (off < 0 || off > offsetofend(struct fuse_args, out_args))
|
||||
return false;
|
||||
|
||||
/* TODO This is garbage. Do it properly */
|
||||
for (i = 0; i < 5; i++) {
|
||||
if (off == offsetof(struct fuse_args, in_args[i].value)) {
|
||||
info->reg_type = PTR_TO_RDONLY_BUF;
|
||||
info->ctx_field_size = 256;
|
||||
if (type != BPF_READ)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (off == offsetof(struct fuse_args, out_args[i].value)) {
|
||||
info->reg_type = PTR_TO_RDWR_BUF;
|
||||
info->ctx_field_size = 256;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (type != BPF_READ)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const struct bpf_verifier_ops fuse_verifier_ops = {
|
||||
.get_func_proto = fuse_prog_func_proto,
|
||||
.is_valid_access = fuse_prog_is_valid_access,
|
||||
};
|
||||
|
||||
const struct bpf_prog_ops fuse_prog_ops = {
|
||||
};
|
||||
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <uapi/linux/btf.h>
|
||||
#include <uapi/linux/bpf.h>
|
||||
#include <uapi/linux/fuse.h>
|
||||
#include <uapi/linux/bpf_perf_event.h>
|
||||
#include <uapi/linux/types.h>
|
||||
#include <linux/seq_file.h>
|
||||
|
|
|
|||
Loading…
Reference in a new issue