bpf, x86: Fix trampoline stack size for 128-bit arguments
Subsystems (2)
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.
[ 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
@@ -2467,10 +2467,8 @@ int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image, void *iu8 *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.