sched_ext: reject oversized exit_dump_len
Subsystems (2)
PATCH v2 1/1 sched_ext: reject oversized exit_dump_len
When a BPF scheduler is enabled, alloc_exit_info() allocates the exit dump buffer with kvzalloc(ops->exit_dump_len). bpf_scx_init_member() stores exit_dump_len from the struct_ops map value without an upper bound, so a length above INT_MAX reaches kvzalloc(), which warns and fails, and the enable fails with -ENOMEM.
bpf_scx_init_member() already rejects oversized dispatch_max_batch and timeout_ms values with -E2BIG. Reject an exit_dump_len above INT_MAX in the same way, so that the map update fails before the value is used.
---
v2:
- Read exit_dump_len once into a local (Tejun)
v1: https://lore.kernel.org/all/[email protected]/
kernel/sched/ext/ext.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
kernel/sched/ext/ext.c +7 -3
@@ -9220,10 +9220,14 @@ static int bpf_scx_init_member(const struct btf_type *t,return -E2BIG ; ops->timeout_ms = *(u32 *)(udata + moff);return 1 ; -case offsetof(struct sched_ext_ops , exit_dump_len): - ops->exit_dump_len = - *(u32 *)(udata + moff) ?:SCX_EXIT_DUMP_DFL_LEN ; +case offsetof(struct sched_ext_ops , exit_dump_len): { +u32 dump_len = *(u32 *)(udata + moff); + +if (dump_len >INT_MAX ) +return -E2BIG ; + ops->exit_dump_len = dump_len ?:SCX_EXIT_DUMP_DFL_LEN ;return 1 ; + }case offsetof(struct sched_ext_ops , hotplug_seq): ops->hotplug_seq = *(u64 *)(udata + moff);return 1 ;
Signature · 1 line
2.56.1
Applied to sched_ext/for-7.5 with the Fixes tag dropped.
Thanks.
--
tejun