Skip to content

Commit 4f83db7

Browse files
sinkapkernel-patches-bot
authored andcommitted
bpf: Expose bpf_d_path helper to sleepable LSM hooks
Sleepable hooks are never called from an NMI/interrupt context, so it is safe to use the bpf_d_path helper in LSM programs attaching to these hooks. The helper is not restricted to sleepable programs and merely uses the list of sleeable hooks as the initial subset of LSM hooks where it can be used. Signed-off-by: KP Singh <kpsingh@google.com>
1 parent 9456636 commit 4f83db7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

kernel/trace/bpf_trace.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/syscalls.h>
1717
#include <linux/error-injection.h>
1818
#include <linux/btf_ids.h>
19+
#include <linux/bpf_lsm.h>
1920

2021
#include <uapi/linux/bpf.h>
2122
#include <uapi/linux/btf.h>
@@ -1178,7 +1179,11 @@ BTF_SET_END(btf_allowlist_d_path)
11781179

11791180
static bool bpf_d_path_allowed(const struct bpf_prog *prog)
11801181
{
1181-
return btf_id_set_contains(&btf_allowlist_d_path, prog->aux->attach_btf_id);
1182+
if (prog->type == BPF_PROG_TYPE_LSM)
1183+
return bpf_lsm_is_sleepable_hook(prog->aux->attach_btf_id);
1184+
1185+
return btf_id_set_contains(&btf_allowlist_d_path,
1186+
prog->aux->attach_btf_id);
11821187
}
11831188

11841189
BTF_ID_LIST_SINGLE(bpf_d_path_btf_ids, struct, path)

0 commit comments

Comments
 (0)