Skip to content

eBPF-based security platform

enforcement: spell the perf ioctl PERF_EVENT_IOC_SET_BPF on both sides

Daniel Borkmann74d96bfc03bd
diff --git a/bpf/bpf2.c b/bpf/bpf2.c
index 8ea78aa6..31763015 100644
--- a/bpf/bpf2.c
+++ b/bpf/bpf2.c
@@ -410,7 +410,7 @@ static __always_inline int shirudo_ioctl(struct file *file, unsigned int cmd,
{
if (ret)
return ret;
- if (cmd == SHIRUDO_PERF_EVENT_IOC_SET_BPF)
+ if (cmd == PERF_EVENT_IOC_SET_BPF)
return shirudo_self_or_deny(SHIRUDO_TAMPER_PERF_ATTACH);
return shirudo_dm_ioctl(file, cmd, ret);
}
diff --git a/include/shirudo/enforcement.h b/include/shirudo/enforcement.h
index 15daeb11..5d45830a 100644
--- a/include/shirudo/enforcement.h
+++ b/include/shirudo/enforcement.h
@@ -7,7 +7,17 @@
#define PR_GET_ENFORCEMENT 0x53520001
#define PR_ENFORCING_ERR 1002
-/* PERF_EVENT_IOC_SET_BPF, _IOW('$', 8, __u32), on every supported architecture. */
-#define SHIRUDO_PERF_EVENT_IOC_SET_BPF 0x40042408u
+/*
+ * vmlinux.h carries no UAPI macros, so BPF code takes the ioctl number
+ * from here: _IOW('$', 8, __u32) on every supported architecture.
+ * Userspace includes the UAPI header first, which defines it as is.
+ */
+#ifdef __bpf__
+#ifndef PERF_EVENT_IOC_SET_BPF
+#define PERF_EVENT_IOC_SET_BPF 0x40042408u
+#endif
+#else
+#include <linux/perf_event.h>
+#endif
#endif /* SHIRUDO_ENFORCEMENT_H */
diff --git a/util/image_guards.c b/util/image_guards.c
index 28da88b4..1c56fead 100644
--- a/util/image_guards.c
+++ b/util/image_guards.c
@@ -25,9 +25,6 @@
#include "paths.h"
#include "tamper.h"
-BUILD_BUG_ON_MSG(SHIRUDO_PERF_EVENT_IOC_SET_BPF != PERF_EVENT_IOC_SET_BPF,
- "the ioctl number the BPF side denies");
-
const struct shirudo_image_guard
shirudo_seal_guards[SEAL_HOOK_COUNT] = {
{ "shirudo_seal_bprm_check_security",