diff mbox series

[RFC,5/9] bpf: introduce CHECK_ATTR_TAIL

Message ID 20211014143436.54470-7-lmb@cloudflare.com (mailing list archive)
State RFC
Delegated to: BPF
Headers show
Series None | expand

Commit Message

Lorenz Bauer Oct. 14, 2021, 2:34 p.m. UTC
---
 kernel/bpf/syscall.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 4e50c0bfdb7d..14c2cfe6ef38 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -719,6 +719,10 @@  int bpf_get_file_flag(int flags)
 		   offsetof(union bpf_attr, CMD##_LAST_FIELD) - \
 		   sizeof(attr->CMD##_LAST_FIELD)) != NULL
 
+#define CHECK_ATTR_TAIL(attr, field) \
+	(memchr_inv((void *)(attr) + offsetofend(typeof(*attr), field), 0, \
+		    sizeof(*(attr)) - offsetofend(typeof(*attr), field)) != NULL ? -EINVAL : 0)
+
 /* dst and src must have at least "size" number of bytes.
  * Return strlen on success and < 0 on error.
  */