Skip to content

Commit 3e00083

Browse files
ThinkerYzu1Martin KaFai Lau
authored andcommitted
bpf: Check cfi_stubs before registering a struct_ops type.
Recently, st_ops->cfi_stubs was introduced. However, the upcoming new struct_ops support (e.g. sched_ext) is not aware of this and does not provide its own cfi_stubs. The kernel ends up NULL dereferencing the st_ops->cfi_stubs. Considering struct_ops supports kernel module now, this NULL check is necessary. This patch is to reject struct_ops registration that does not provide a cfi_stubs. Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com> Link: https://lore.kernel.org/r/20240222021105.1180475-2-thinker.li@gmail.com Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
1 parent 58fd62e commit 3e00083

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

kernel/bpf/bpf_struct_ops.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ int bpf_struct_ops_desc_init(struct bpf_struct_ops_desc *st_ops_desc,
302302
}
303303
sprintf(value_name, "%s%s", VALUE_PREFIX, st_ops->name);
304304

305+
if (!st_ops->cfi_stubs) {
306+
pr_warn("struct_ops for %s has no cfi_stubs\n", st_ops->name);
307+
return -EINVAL;
308+
}
309+
305310
type_id = btf_find_by_name_kind(btf, st_ops->name,
306311
BTF_KIND_STRUCT);
307312
if (type_id < 0) {

0 commit comments

Comments
 (0)