From: sashiko-bot@kernel.org
To: "Pu Lehui" <pulehui@huaweicloud.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v6 6/7] riscv, bpf: Mixing bpf2bpf and tailcalls
Date: Wed, 08 Jul 2026 07:07:35 +0000 [thread overview]
Message-ID: <20260708070736.47B571F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260708064436.2971933-7-pulehui@huaweicloud.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Uninitialized Tail Call Count (TCC) in synchronous BPF callbacks allows bypassing tail call limits, leading to kernel stack overflow or DoS.
--
--- Patch [6]: [PATCH bpf-next v6 6/7] riscv, bpf: Mixing bpf2bpf and tailcalls ---
commit c63e8081e54742ee045ae19d7f5fc9de4b31396f
Author: Pu Lehui <pulehui@huawei.com>
riscv, bpf: Mixing bpf2bpf and tailcalls
This commit implements mixing bpf2bpf and tailcalls for the RV64 JIT,
similar to x86_64, by using a non-callee saved register to transfer the
TCC between functions and saving that register to the stack. It stores the
TCC back to the stack after bpf2bpf calls or calling the original bpf
func in a bpf trampoline.
> diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
> index 7c6304e0b846a..823262ca47ebf 100644
> --- a/arch/riscv/net/bpf_jit_comp64.c
> +++ b/arch/riscv/net/bpf_jit_comp64.c
[ ... ]
> @@ -2038,11 +2038,10 @@ void bpf_jit_build_prologue(struct rv_jit_context *ctx, bool is_subprog)
> for (i = 0; i < RV_FENTRY_NINSNS; i++)
> emit(rv_nop(), ctx);
>
> - /* First instruction is always setting the tail-call-counter
> - * (TCC) register. This instruction is skipped for tail calls.
> - * Force using a 4-byte (non-compressed) instruction.
> - */
> - emit(rv_addi(RV_REG_TCC, RV_REG_ZERO, MAX_TAIL_CALL_CNT), ctx);
> + if (!is_subprog)
> + emit(rv_addi(RV_REG_TCC, RV_REG_ZERO, MAX_TAIL_CALL_CNT), ctx);
> +
[Severity: High]
Does skipping TCC initialization for all subprograms leave the TCC uninitialized
for synchronous BPF callbacks?
If a BPF program uses a C helper like bpf_loop() to invoke a synchronous
callback (which is treated as a subprogram where is_subprog is true), the C
helper will have clobbered the RV_REG_TCC (A6) register.
Because the callback skips initializing the TCC, it will inherit whatever
garbage value was left in A6 and save it to the stack. If this callback then
calls another subprogram that executes a tail call, could this garbage TCC
value bypass the tail-call limit, leading to unbounded tail calls and
a kernel stack overflow?
> + /* tailcall starts here, emit insn before it must be fixed */
>
> emit_addi(RV_REG_SP, RV_REG_SP, -stack_adjust, ctx);
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260708064436.2971933-1-pulehui@huaweicloud.com?part=6
next prev parent reply other threads:[~2026-07-08 7:07 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 6:44 [PATCH bpf-next v6 0/7] Mixing bpf2bpf and tailcalls for RV64 Pu Lehui
2026-07-08 6:44 ` Pu Lehui
2026-07-08 6:44 ` [PATCH bpf-next v6 1/7] bpf: Extract the is_struct_ops_tramp helper Pu Lehui
2026-07-08 6:44 ` Pu Lehui
2026-07-08 6:44 ` [PATCH bpf-next v6 2/7] riscv, bpf: Fix memory leak in bpf_jit_free Pu Lehui
2026-07-08 6:44 ` Pu Lehui
2026-07-08 6:54 ` sashiko-bot
2026-07-08 8:51 ` Pu Lehui
2026-07-09 8:46 ` Daniel Borkmann
2026-07-08 6:44 ` [PATCH bpf-next v6 3/7] riscv, bpf: Using kvzalloc_objs to allocate cache buffer Pu Lehui
2026-07-08 6:44 ` Pu Lehui
2026-07-08 6:44 ` [PATCH bpf-next v6 4/7] riscv, bpf: Fix kernel stack corruption in tailcall with CFI Pu Lehui
2026-07-08 6:44 ` Pu Lehui
2026-07-08 6:44 ` [PATCH bpf-next v6 5/7] riscv, bpf: Add RV_TAILCALL_OFFSET macro to format tailcall offset Pu Lehui
2026-07-08 6:44 ` Pu Lehui
2026-07-08 6:44 ` [PATCH bpf-next v6 6/7] riscv, bpf: Mixing bpf2bpf and tailcalls Pu Lehui
2026-07-08 6:44 ` Pu Lehui
2026-07-08 7:07 ` sashiko-bot [this message]
2026-07-08 8:48 ` Pu Lehui
2026-07-08 7:35 ` bot+bpf-ci
2026-07-08 7:35 ` bot+bpf-ci
2026-07-08 8:54 ` Pu Lehui
2026-07-08 8:54 ` Pu Lehui
2026-07-09 11:37 ` Björn Töpel
2026-07-09 11:37 ` Björn Töpel
2026-07-09 15:09 ` Pu Lehui
2026-07-09 15:09 ` Pu Lehui
2026-07-09 19:51 ` Björn Töpel
2026-07-09 19:51 ` Björn Töpel
2026-07-10 0:53 ` Pu Lehui
2026-07-10 0:53 ` Pu Lehui
2026-07-10 9:43 ` Daniel Borkmann
2026-07-10 9:43 ` Daniel Borkmann
2026-07-08 6:44 ` [PATCH bpf-next v6 7/7] selftests/bpf: Remove tailcalls tests from DENYLIST.riscv64 Pu Lehui
2026-07-08 6:44 ` Pu Lehui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260708070736.47B571F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=pulehui@huaweicloud.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.