mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: a.s.protopopov@gmail.com,ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,eddyz87@gmail.com,memxor@gmail.com,almagui@kernel.org,john.fastabend@gmail.com,qmo@kernel.org,brauner@kernel.org,kpsingh@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,ihor.solodrai@linux.dev,sashal@kernel.org,bpf@vger.kernel.org,linux-kernel@vger.kernel.org
Cc: a.s.protopopov@gmail.com,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH v3 bpf-next 13/18] bpf: Check the return values of fmod_ret programs on found targets
Date: Wed, 11 Nov 2026 08:21:42 +0000 (UTC)	[thread overview]
Message-ID: <c4f98afcae91b54b30f5e9fdab98125cdccf00b1c7a71afff1b16e931798c314@mail.kernel.org> (raw)
In-Reply-To: <20261110164046.454431-14-a.s.protopopov@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2481 bytes --]

> bpf: Check the return values of fmod_ret programs on found targets

TL;DR: Possible wrong behaviour: fmod_ret programs on 64-bit found targets
don't require the JIT, so in the interpreter -14 may reach callers as
4294967282; a later commit fixes this, leaving a narrow gap here.

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c

[ ... ]

> +static int fmodret_retval_init(struct bpf_verifier_env *env, u32 btf_id,
> +			       unsigned long addr, const char *tname)
> +{

[ ... ]

> +	if (!cnt)
> +		goto invalid;
> +
> +	aux->fmodret_retvals = retvals;
> +	aux->fmodret_retval_cnt = cnt;
> +	return 0;

For a found target that returns a 64-bit integer (size == 8),
check_fmodret_retval() accepts the full 64-bit R0, so "r0 = -14" is
accepted as the s64 value -14.  Nothing here makes such a program require
the JIT.

If the program runs in the interpreter, prog->bpf_func is
__bpf_prog_runN(), which is declared in kernel/bpf/core.c as:

  static unsigned int PROG_NAME(stack_size)(const void *ctx,
                                            const struct bpf_insn *insn)

so only the low 32 bits of R0 come back.  The x86 trampoline handles
interpreted programs, stores all of RAX and returns it to the caller of
the traced function, so the caller of a long-returning found target would
see 4294967282 instead of -14.

That value is non-zero, so the function body is skipped, but it is not an
error value either.  Callers would treat the skipped call as a success
that returned a large positive value, which is the case the commit message
says the check is meant to prevent ("Returning such a value instead of
calling the function looks to the callers like a real failure").

Should fmodret_retval_init() set env->prog->jit_required = 1 when
size == 8?  A later commit in this series, c4a7eee0c4d7 ("bpf: Require the
JIT for fmod_ret programs on found 64-bit targets"), adds
"if (size == 8) env->prog->jit_required = 1;" right after these
assignments.  No found target carries the tag until 8659bd72073c
("resolve_btfids: Tag fmod_ret candidates as targets"), which comes after
that fix, so the window is narrow, but it is still a gap in this commit's
own logic.


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/42981885558

  reply	other threads:[~2026-11-11  8:21 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 16:40 [PATCH v3 bpf-next 00/18] Auto-detect BPF fmodret targets Anton Protopopov
2026-11-10 16:40 ` [PATCH v3 bpf-next 01/18] bpf: Add BTF ID sets for fmod_ret targets Anton Protopopov
2026-11-11  8:01   ` bot+bpf-ci
2026-11-10 16:40 ` [PATCH v3 bpf-next 02/18] bpf: Add a btf_id_set8_entry helper Anton Protopopov
2026-11-10 16:40 ` [PATCH v3 bpf-next 03/18] bpf: Build fmod_ret target sets from BTF decl tags Anton Protopopov
2026-11-10 16:40 ` [PATCH v3 bpf-next 04/18] selftests/bpf: Declare bpf_fentry_test1 in tracing tests Anton Protopopov
2026-11-10 16:40 ` [PATCH v3 bpf-next 05/18] bpf: Declare fmod_ret targets with BTF_FMODRET sets Anton Protopopov
2026-11-10 16:40 ` [PATCH v3 bpf-next 06/18] selftests/bpf: Test fmod_ret BTF decl tags and attach permission Anton Protopopov
2026-11-10 16:40 ` [PATCH v3 bpf-next 07/18] scripts: Add LLVM plugin infrastructure Anton Protopopov
2026-11-10 16:40 ` [PATCH v3 bpf-next 08/18] bpf: Add the bpf_scan_ir LLVM plugin Anton Protopopov
2026-11-11  8:21   ` bot+bpf-ci
2026-11-10 16:40 ` [PATCH v3 bpf-next 09/18] bpf: Find fmod_ret candidates in bpf_scan_ir Anton Protopopov
2026-11-10 16:40 ` [PATCH v3 bpf-next 10/18] bpf: Allow writes to private stack objects " Anton Protopopov
2026-11-10 16:40 ` [PATCH v3 bpf-next 11/18] bpf: Follow PHIs " Anton Protopopov
2026-11-10 16:40 ` [PATCH v3 bpf-next 12/18] bpf: Follow integer casts " Anton Protopopov
2026-11-10 16:40 ` [PATCH v3 bpf-next 13/18] bpf: Check the return values of fmod_ret programs on found targets Anton Protopopov
2026-11-11  8:21   ` bot+bpf-ci [this message]
2026-11-10 16:40 ` [PATCH v3 bpf-next 14/18] bpf: Require the JIT for fmod_ret programs on found 64-bit targets Anton Protopopov
2026-11-10 16:40 ` [PATCH v3 bpf-next 15/18] resolve_btfids: Tag fmod_ret candidates as targets Anton Protopopov
2026-11-11  8:21   ` bot+bpf-ci
2026-11-10 16:40 ` [PATCH v3 bpf-next 16/18] selftests/bpf: Test fmod_ret candidates found by bpf_scan_ir Anton Protopopov
2026-11-10 16:40 ` [PATCH v3 bpf-next 17/18] selftests/bpf: Enable bpf_scan_ir in the config Anton Protopopov
2026-11-10 16:40 ` [PATCH v3 bpf-next 18/18] bpftool: List and show fmod_ret targets Anton Protopopov

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=c4f98afcae91b54b30f5e9fdab98125cdccf00b1c7a71afff1b16e931798c314@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=a.s.protopopov@gmail.com \
    --cc=almagui@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brauner@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=mason@kernel.org \
    --cc=memxor@gmail.com \
    --cc=qmo@kernel.org \
    --cc=sashal@kernel.org \
    --cc=yonghong.song@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®