summaryrefslogtreecommitdiff
path: root/kernel/bpf/cpumask.c
diff options
context:
space:
mode:
authorDavid Vernet <void@manifault.com>2023-01-28 17:15:37 +0300
committerAlexei Starovoitov <ast@kernel.org>2023-01-28 23:21:40 +0300
commitcb4a21ea592f5753ab54cd8688306cf6423783a8 (patch)
treefdcc4ac5a343d517505452918798e38615e8e097 /kernel/bpf/cpumask.c
parent70eb3911d80f548a76fb9a40c8a3fd93ac061a42 (diff)
downloadlinux-cb4a21ea592f5753ab54cd8688306cf6423783a8.tar.xz
bpf: Build-time assert that cpumask offset is zero
The first element of a struct bpf_cpumask is a cpumask_t. This is done to allow struct bpf_cpumask to be cast to a struct cpumask. If this element were ever moved to another field, any BPF program passing a struct bpf_cpumask * to a kfunc expecting a const struct cpumask * would immediately fail to load. Add a build-time assertion so this is assumption is captured and verified. Signed-off-by: David Vernet <void@manifault.com> Link: https://lore.kernel.org/r/20230128141537.100777-1-void@manifault.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel/bpf/cpumask.c')
-rw-r--r--kernel/bpf/cpumask.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/kernel/bpf/cpumask.c b/kernel/bpf/cpumask.c
index 25355a0a367a..6bbb67dfc998 100644
--- a/kernel/bpf/cpumask.c
+++ b/kernel/bpf/cpumask.c
@@ -52,6 +52,9 @@ struct bpf_cpumask *bpf_cpumask_create(void)
{
struct bpf_cpumask *cpumask;
+ /* cpumask must be the first element so struct bpf_cpumask be cast to struct cpumask. */
+ BUILD_BUG_ON(offsetof(struct bpf_cpumask, cpumask) != 0);
+
cpumask = bpf_mem_alloc(&bpf_cpumask_ma, sizeof(*cpumask));
if (!cpumask)
return NULL;