sched_ext: reject oversized exit_dump_len
Subsystems (2)
PATCH 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.
--- kernel/sched/ext/ext.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/sched/ext/ext.c +2 -0
@@ -9221,6 +9221,8 @@ static int bpf_scx_init_member(const struct btf_type *t, ops->timeout_ms = *(u32 *)(udata + moff);return 1 ;case offsetof(struct sched_ext_ops , exit_dump_len): +if (*(u32 *)(udata + moff) >INT_MAX ) +return -E2BIG ; ops->exit_dump_len = *(u32 *)(udata + moff) ?:SCX_EXIT_DUMP_DFL_LEN ;return 1 ;
Signature · 1 line
2.56.1
Tejun Heo
reviewerHello, Sechang.
kernel/sched/ext/ext.c static int bpf_scx_init_member(const struct btf_type *t, · line 9227
Quoted 5 lines · Sechang Lim
kernel/sched/ext/ext.c +2
-0case offsetof(struct sched_ext_ops , exit_dump_len): +if (*(u32 *)(udata + moff) >INT_MAX ) +return -E2BIG ; ops->exit_dump_len = *(u32 *)(udata + moff) ?:SCX_EXIT_DUMP_DFL_LEN ;
Maybe read the field once into a local and test that?
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;
}Thanks.
--
tejun
Quoted 12 lines · Tejun Heo
Hello, Sechang.
kernel/sched/ext/ext.c static int bpf_scx_init_member(const struct btf_type *t, · line 9227
Quoted 5 lines · Sechang Lim
kernel/sched/ext/ext.c +2
-0case offsetof(struct sched_ext_ops , exit_dump_len): +if (*(u32 *)(udata + moff) >INT_MAX ) +return -E2BIG ; ops->exit_dump_len = *(u32 *)(udata + moff) ?:SCX_EXIT_DUMP_DFL_LEN ;Maybe read the field once into a local and test that?
Review
Quoted 8 lines
(quoted diff) +0
-0case 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; }
Sure, will do in v2.
Thanks,
Sechang