Skip to contentSkip to conversation

sched_ext: reject oversized exit_dump_len

PATCH Superseded Sechang Lim 2 participants 3 messages Nov 24

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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.

Fixes 07814a9439a3 ("sched_ext: Print debug dump after an error exit")
---
 kernel/sched/ext/ext.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/sched/ext/ext.c +2 -0
index 10de6bd865e8..6dfe70249a7d 100644
@@ -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
reviewer
#1 lore raw

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 -0
 	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;

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

#2 lore raw
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 -0
 	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;

Maybe read the field once into a local and test that?

Review

Quoted 8 lines
(quoted diff) +0 -0
 	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;
 	}

Sure, will do in v2.

Thanks,
Sechang