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.12.y v2 1/2] bpf: Invalidate dynptr slices by dynptr_id on release
Date: Sat, 29 Aug 2026 03:56:59 +0000	[thread overview]
Message-ID: <20260829035700.044281F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260829033725.2365697-2-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` function reads the `dynptr_id` union field without verifying the register's type, causing it to erroneously invalidate unrelated registers due to memory aliasing.
--

commit e9eb0688f5ef0c81c32aeb93616da3b5719b04da
Author: Amery Hung <ameryhung@gmail.com>
bpf: Invalidate dynptr slices by dynptr_id on release

This patch invalidates dynptr slices when their parent dynptr is released by
walking registers with a matching dynptr_id in unmark_stack_slots_dynptr().
This addresses an issue where LDX/STX through slices remains allowed after
submitting or discarding the dynptr.

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

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 99b3f539e431f..5d0874a09a8db 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
[ ... ]
> @@ -862,6 +874,17 @@ static void mark_reg_invalid(const struct bpf_verifier_env *env, struct bpf_reg_
>  		__mark_reg_unknown(env, reg);
>  }
>  
> +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]
Does this code risk misinterpreting union fields in unrelated registers
due to memory aliasing in invalidate_slices_of_dynptr()?

Because dynptr_id shares a union with other fields in struct bpf_reg_state
(such as btf_id on 32-bit architectures, or first_slot for dynptrs), if the
register is not explicitly checked for type PTR_TO_MEM, this comparison
might match unrelated registers.

For instance, a program that acquires a dynptr reference (assigning it
id_gen = 1) could use a register where the union happens to alias to 1
(like a CONST_PTR_TO_DYNPTR callback argument where first_slot = true, or a
PTR_TO_BTF_ID where the BTF ID is 1). Releasing the dynptr triggers
invalidate_slices_of_dynptr(env, 1), which unconditionally checks
dreg->dynptr_id == 1 and misinterprets the aliased union field as a match.
This could incorrectly invalidate valid registers, leading to spurious
verification failures.

Could we add a check for dreg->type before accessing dreg->dynptr_id to
prevent this?

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

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

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

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-29  3:37 [PATCH 6.12.y v2 0/2] bpf: fix dynptr lifetime invalidation on release Xu Yunxiang
2026-08-29  3:37 ` [PATCH 6.12.y v2 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.12.y v2 2/2] bpf: Invalidate dynptr clones in every call frame " Xu Yunxiang
2026-08-29  4:01   ` sashiko-bot
2026-08-29 10:26 ` [PATCH 6.12.y v3 0/3] bpf: fix dynptr release handling Xu Yunxiang
2026-08-29 10:26   ` [PATCH 6.12.y v3 1/3] bpf: Invalidate dynptr slices by dynptr_id on release Xu Yunxiang
2026-08-29 10:26   ` [PATCH 6.12.y v3 2/3] bpf: Propagate referenced dynptr release errors Xu Yunxiang
2026-08-29 10:48     ` sashiko-bot
2026-08-29 10:26   ` [PATCH 6.12.y v3 3/3] bpf: Invalidate dynptr clones in every call frame on release Xu Yunxiang

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=20260829035700.044281F000E9@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.