Add a new bpf_current_capable kfunc to check whether the current task has a specific capability. In our use case, we will use it in a lsm bpf program to help identify if the user operation is permitted. Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx> --- kernel/bpf/helpers.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index eb91cae..bbee7ea 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -2429,6 +2429,11 @@ __bpf_kfunc void bpf_rcu_read_unlock(void) rcu_read_unlock(); } +__bpf_kfunc bool bpf_current_capable(int cap) +{ + return has_capability(current, cap); +} + __diag_pop(); BTF_SET8_START(generic_btf_ids) @@ -2456,6 +2461,7 @@ __bpf_kfunc void bpf_rcu_read_unlock(void) BTF_ID_FLAGS(func, bpf_task_under_cgroup, KF_RCU) #endif BTF_ID_FLAGS(func, bpf_task_from_pid, KF_ACQUIRE | KF_RET_NULL) +BTF_ID_FLAGS(func, bpf_current_capable, KF_RCU) BTF_SET8_END(generic_btf_ids) static const struct btf_kfunc_id_set generic_kfunc_set = { -- 1.8.3.1