]> Git Repo - J-linux.git/commitdiff
bpf: Expose bpf_d_path helper to sleepable LSM hooks
authorKP Singh <[email protected]>
Fri, 13 Nov 2020 00:59:30 +0000 (00:59 +0000)
committerDaniel Borkmann <[email protected]>
Fri, 13 Nov 2020 14:47:21 +0000 (15:47 +0100)
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]
kernel/trace/bpf_trace.c

index cfce60ad1cb5c2a6b6564fce178216bf7ffb470c..02986c7b90eb04a6f4b03cc8c8c68910feb30923 100644 (file)
@@ -16,6 +16,8 @@
 #include <linux/syscalls.h>
 #include <linux/error-injection.h>
 #include <linux/btf_ids.h>
+#include <linux/bpf_lsm.h>
+
 #include <net/bpf_sk_storage.h>
 
 #include <uapi/linux/bpf.h>
@@ -1179,7 +1181,11 @@ BTF_SET_END(btf_allowlist_d_path)
 
 static bool bpf_d_path_allowed(const struct bpf_prog *prog)
 {
-       return btf_id_set_contains(&btf_allowlist_d_path, prog->aux->attach_btf_id);
+       if (prog->type == BPF_PROG_TYPE_LSM)
+               return bpf_lsm_is_sleepable_hook(prog->aux->attach_btf_id);
+
+       return btf_id_set_contains(&btf_allowlist_d_path,
+                                  prog->aux->attach_btf_id);
 }
 
 BTF_ID_LIST_SINGLE(bpf_d_path_btf_ids, struct, path)
This page took 0.063594 seconds and 4 git commands to generate.