Skip to contentSkip to conversation

bpf, x86: Fix trampoline stack size for 128-bit arguments

PATCH New Artem Dinaburg 1 participant 1 message Oct 21

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf, x86: Fix trampoline stack size for 128-bit arguments

From: Yonghong Song <[email protected]>

[ Upstream commit 814cba835ef648e0c5eb79505c96c0493b29eea6 ]

btf_distill_func_proto() accepts a function argument up to 16 bytes, so a 128-bit scalar such as __int128 reaches the x86 trampoline with arg_size == 16. But the current implementation assumes an __int128 argument only needs one register, so the register save area is under-allocated and save_args() overwrites adjacent stack slots.

Compute the register count from arg_size for all arguments to fix it.

Fixes a9c5ad31fbdc ("bpf: x86: Support in-register struct arguments in trampoline programs")
Assisted-by LLM

[ Backport to 6.6.y: Remove the struct-only guard from the existing
unbraced argument loop; count eight-byte slots for every argument. ]

---
Hi,

Please consider this backport of the fix for CVE-2026-90358 to 6.6.y.

The backport removes the struct-only guard from the existing unbraced argument loop. See the bracketed backport note above.

The complete fix is already present in 6.12.y, 6.18.y and 7.2.y.

Build-tested only as part of a cumulative 6.6.y series on x86_64 (allmodconfig, CONFIG_WERROR=y); no runtime testing.

Thanks,
Artem Dinaburg

 arch/x86/net/bpf_jit_comp.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/x86/net/bpf_jit_comp.c +1 -3
index 8028a5a4ab64570022c15bfdf220c4033ad0d4ab..3d33aafa2cc26541e64b37960ce20a06ce5fd2d8 100644
@@ -2467,10 +2467,8 @@ int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image, void *i
 	u8 *prog;
 	bool save_ret;
 
-	/* extra registers for struct arguments */
 	for (i = 0; i < m->nr_args; i++)
-		if (m->arg_flags[i] & BTF_FMODEL_STRUCT_ARG)
-			nr_regs += (m->arg_size[i] + 7) / 8 - 1;
+		nr_regs += (m->arg_size[i] + 7) / 8 - 1;
 
 	/* x86-64 supports up to MAX_BPF_FUNC_ARGS arguments. 1-6
 	 * are passed through regs, the remains are through stack.