All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xu Yunxiang" <xyx2021@mail.ustc.edu.cn>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH 6.6.y 1/2] bpf: Invalidate dynptr slices by dynptr_id on release
Date: Sat, 29 Aug 2026 03:56:13 +0000	[thread overview]
Message-ID: <20260829035613.733421F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260829033645.2365631-1-xyx2021@mail.ustc.edu.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The newly added `invalidate_slices_of_dynptr()` accesses `dreg->dynptr_id` without verifying that `dreg->type` is `PTR_TO_MEM` or `PTR_TO_MEM | PTR_MAYBE_NULL`. Because `dynptr_id` is part of a union in `struct bpf_reg_state`, this leads to unsafe alias reads and incorrect register invalidation.
--

commit e7cd53e464cb9cab28779b0a9fe2dde83ad7d53c
Author: Amery Hung <ameryhung@gmail.com>

bpf: Invalidate dynptr slices by dynptr_id on release

This patch invalidates dynptr slices by matching dynptr_id when a dynptr is
released. It adds invalidate_slices_of_dynptr() to iterate over registers
and invalidate those matching the released dynptr_id.

Link: https://lore.kernel.org/r/20260529014936.2811085-6-ameryhung@gmail.com

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
[ ... ]
> +static void invalidate_slices_of_dynptr(struct bpf_verifier_env *env, int dynptr_id)
> +{
> +	struct bpf_func_state *fstate;
> +	struct bpf_reg_state *dreg;
> +
> +	bpf_for_each_reg_in_vstate(env->cur_state, fstate, dreg, ({
> +		if (dreg->dynptr_id == dynptr_id)
[Severity: High]
Is it safe to read dreg->dynptr_id here without checking the register type?

Because dynptr_id is part of a union in struct bpf_reg_state, it aliases
other fields like btf_id and map_uid (especially on 32-bit systems where
these fields occupy the same bytes).

If a register holds a PTR_TO_BTF_ID or an inner map PTR_TO_MAP_VALUE, and
its btf_id or map_uid happens to match the released dynptr_id, could this
result in a false positive that invalidates an unrelated valid register?

For comparison, destroy_if_dynptr_stack_slot() restricts this check:

    if (dreg->type != (PTR_TO_MEM | PTR_MAYBE_NULL) &&
        dreg->type != PTR_TO_MEM)
        continue;
    if (dreg->dynptr_id == dynptr_id)
        mark_reg_invalid(env, dreg);

Should invalidate_slices_of_dynptr() include a similar type check before
accessing dynptr_id?

> +			mark_reg_invalid(env, dreg);
> +	}));
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260829032754.2324760-1-xyx2021@mail.ustc.edu.cn?part=1

  reply	other threads:[~2026-08-29  3:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-29  3:27 [PATCH 6.6.y 0/2] bpf: fix dynptr lifetime invalidation on release Xu Yunxiang
2026-08-29  3:36 ` [PATCH 6.6.y 1/2] bpf: Invalidate dynptr slices by dynptr_id " Xu Yunxiang
2026-08-29  3:56   ` sashiko-bot [this message]
2026-08-29  3:37 ` [PATCH 6.6.y 2/2] bpf: Invalidate dynptr clones in every call frame " Xu Yunxiang
2026-08-29  4:07   ` sashiko-bot
2026-09-09  4:28     ` [PATCH bpf 0/2] bpf: Preserve escaped dynptr slice ancestry Xu Yunxiang
2026-09-09  4:28       ` [PATCH bpf 1/2] bpf: Preserve escaped dynptr slice ancestry on subprog return Xu Yunxiang
2026-09-09  5:18         ` bot+bpf-ci
2026-09-09  4:28       ` [PATCH bpf 2/2] selftests/bpf: Test slices escaping a clone call frame Xu Yunxiang
2026-09-09  4:34         ` sashiko-bot
2026-09-09  5:18         ` bot+bpf-ci
2026-08-29 10:26 ` [PATCH 6.6.y v2 0/3] bpf: fix dynptr release handling Xu Yunxiang
2026-08-29 10:26   ` [PATCH 6.6.y v2 1/3] bpf: Invalidate dynptr slices by dynptr_id on release Xu Yunxiang
2026-08-29 10:26   ` [PATCH 6.6.y v2 2/3] bpf: Propagate referenced dynptr release errors Xu Yunxiang
2026-08-29 10:42     ` sashiko-bot
2026-08-29 10:26   ` [PATCH 6.6.y v2 3/3] bpf: Invalidate dynptr clones in every call frame on release Xu Yunxiang
2026-08-30  2:56   ` [PATCH 6.6.y v2 0/3] bpf: fix dynptr release handling Sasha Levin

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=20260829035613.733421F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xyx2021@mail.ustc.edu.cn \
    /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.