From: sashiko-bot@kernel.org
To: "Alexis Lothoré (eBPF Foundation)" <alexis.lothore@bootlin.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v4 01/10] bpf: propagate original instruction offset when patching program
Date: Wed, 08 Jul 2026 08:19:36 +0000 [thread overview]
Message-ID: <20260708081937.5D5031F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260708-kasan-v4-1-d5c177ab8227@bootlin.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Incorrect or inconsistent calculation of `insn_off_in_patch` causes loss or misassignment of `aux_data`.
- [Medium] A single `insn_off_in_patch` integer is insufficient to propagate KASAN memory markings to patches that emit multiple memory accesses.
--
--- Patch [1]: [PATCH bpf-next v4 01/10] bpf: propagate original instruction offset when patching program ---
commit 6ebaaf2368d2745f393ec38eb53d5857d5ec62b8
Author: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
bpf: propagate original instruction offset when patching program
When the verifier patches an ebpf program with bpf_patch_insn_data, it
then calls adjust_insn_aux_data to make sure that insn_aux_data takes
into account the newly inserted patch.
> diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
> index 12a8a4eb757f1..f515fc9669ce2 100644
> --- a/kernel/bpf/fixups.c
> +++ b/kernel/bpf/fixups.c
[ ... ]
> @@ -856,16 +862,20 @@ int bpf_convert_ctx_accesses(struct bpf_verifier_env *env)
> if (!ops->convert_ctx_access)
> continue;
> convert_ctx_access = ops->convert_ctx_access;
> + insn_off_in_patch = 0;
[Severity: Medium]
Will this properly track context accesses that are converted into multiple
chained memory loads?
By relying on a single integer to track the offset, it seems we might fail to
account for multi-load patches emitted by ops->convert_ctx_access() (for
example, reading skb->dev followed by dev->ifindex). The secondary memory
accesses will receive zeroed aux_data and lack the required KASAN
non_stack_access marking.
Additionally, since the original instruction is completely replaced here, does
it make sense to unconditionally assign its aux_data to the first generated
instruction, which might not even be the actual memory access?
> break;
[ ... ]
> @@ -1464,7 +1475,7 @@ static int add_hidden_subprog(struct bpf_verifier_env *env, struct bpf_insn *pat
> * ones for the hidden subprog. Hence all of the adjustment operations
> * in bpf_patch_insn_data are no-ops.
> */
> - prog = bpf_patch_insn_data(env, env->prog->len - 1, patch, len);
> + prog = bpf_patch_insn_data(env, env->prog->len - 1, patch, len, -1);
[Severity: Medium]
Is it intentional to pass -1 for the offset here?
Since the original instruction is explicitly preserved in the patch buffer
in bpf_do_misc_fixups():
*patch++ = env->prog->insnsi[insn_cnt - 1];
Passing -1 to bpf_patch_insn_data() will cause the aux_data associated with
that instruction to be lost.
[ ... ]
> @@ -1743,7 +1765,8 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env)
> *patch++ = BPF_ALU64_IMM(BPF_MUL, off_reg, -1);
> cnt = patch - insn_buf;
>
> - new_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);
> + new_prog = bpf_patch_insn_data(env, i + delta, insn_buf,
> + cnt, -1);
[Severity: Medium]
In this pointer arithmetic rewrite, the original ALU instruction is preserved
in the patch buffer (*patch++ = *insn).
Should we calculate and pass its exact offset inside the patch buffer instead
of passing -1, which discards its aux_data?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260708-kasan-v4-0-d5c177ab8227@bootlin.com?part=1
next prev parent reply other threads:[~2026-07-08 8:19 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 8:00 [PATCH bpf-next v4 00/10] bpf: add support for KASAN checks in JITed programs Alexis Lothoré (eBPF Foundation)
2026-07-08 8:00 ` [PATCH bpf-next v4 01/10] bpf: propagate original instruction offset when patching program Alexis Lothoré (eBPF Foundation)
2026-07-08 8:19 ` sashiko-bot [this message]
2026-07-08 14:11 ` Alexis Lothoré
2026-07-08 8:00 ` [PATCH bpf-next v4 02/10] bpf: mark instructions accessing program stack Alexis Lothoré (eBPF Foundation)
2026-07-08 8:10 ` sashiko-bot
2026-07-08 14:15 ` Alexis Lothoré
2026-07-08 8:00 ` [PATCH bpf-next v4 03/10] bpf: add BPF_JIT_KASAN for KASAN instrumentation of JITed programs Alexis Lothoré (eBPF Foundation)
2026-07-08 12:48 ` Andrey Konovalov
2026-07-08 8:00 ` [PATCH bpf-next v4 04/10] bpf, x86: add helper to emit kasan checks in x86 " Alexis Lothoré (eBPF Foundation)
2026-07-08 8:16 ` sashiko-bot
2026-07-08 14:20 ` Alexis Lothoré
2026-07-08 8:00 ` [PATCH bpf-next v4 05/10] bpf, x86: refactor BPF_ST management in do_jit Alexis Lothoré (eBPF Foundation)
2026-07-08 8:00 ` [PATCH bpf-next v4 06/10] bpf, x86: emit KASAN checks into x86 JITed programs Alexis Lothoré (eBPF Foundation)
2026-07-08 8:16 ` sashiko-bot
2026-07-08 14:29 ` Alexis Lothoré
2026-07-08 8:00 ` [PATCH bpf-next v4 07/10] bpf, x86: enable KASAN for JITed programs on x86 Alexis Lothoré (eBPF Foundation)
2026-07-08 8:19 ` sashiko-bot
2026-07-08 14:33 ` Alexis Lothoré
2026-07-08 8:00 ` [PATCH bpf-next v4 08/10] selftests/bpf: add helper to check whether eBPF KASAN is active Alexis Lothoré (eBPF Foundation)
2026-07-08 8:00 ` [PATCH bpf-next v4 09/10] selftests/bpf: move bpf_jit_harden helper into testing_helpers Alexis Lothoré (eBPF Foundation)
2026-07-08 8:16 ` sashiko-bot
2026-07-08 14:43 ` Alexis Lothoré
2026-07-08 8:00 ` [PATCH bpf-next v4 10/10] selftests/bpf: add tests to validate KASAN on JIT programs Alexis Lothoré (eBPF Foundation)
2026-07-08 8:28 ` sashiko-bot
2026-07-08 14:47 ` Alexis Lothoré
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=20260708081937.5D5031F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alexis.lothore@bootlin.com \
--cc=bpf@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox