#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>
 
 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)