Skip to content

Commit 6f10064

Browse files
sinkapborkmann
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 sleepable hooks as the initial subset of LSM hooks where it can be used. Signed-off-by: KP Singh <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 423f161 commit 6f10064

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

kernel/trace/bpf_trace.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <linux/syscalls.h>
1717
#include <linux/error-injection.h>
1818
#include <linux/btf_ids.h>
19+
#include <linux/bpf_lsm.h>
20+
1921
#include <net/bpf_sk_storage.h>
2022

2123
#include <uapi/linux/bpf.h>
@@ -1179,7 +1181,11 @@ BTF_SET_END(btf_allowlist_d_path)
11791181

11801182
static bool bpf_d_path_allowed(const struct bpf_prog *prog)
11811183
{
1182-
return btf_id_set_contains(&btf_allowlist_d_path, prog->aux->attach_btf_id);
1184+
if (prog->type == BPF_PROG_TYPE_LSM)
1185+
return bpf_lsm_is_sleepable_hook(prog->aux->attach_btf_id);
1186+
1187+
return btf_id_set_contains(&btf_allowlist_d_path,
1188+
prog->aux->attach_btf_id);
11831189
}
11841190

11851191
BTF_ID_LIST_SINGLE(bpf_d_path_btf_ids, struct, path)

0 commit comments

Comments
 (0)