BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yiyang Chen" <chenyy23@mails.tsinghua.edu.cn>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 2/2] selftests/bpf: Cover refcount acquire node offsets
Date: Fri, 19 Jun 2026 08:30:59 +0000	[thread overview]
Message-ID: <20260619083059.985F21F000E9@smtp.kernel.org> (raw)
In-Reply-To: <264dd4a10d3abdd037e01ccc6da44e5a5758dee2.1781852308.git.chenyy23@mails.tsinghua.edu.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Logical double-free and verifier rejection in bpf_list_push_front error paths.
--

commit 822cb053457c04aa9becab9c713d49977dc74582
Author: Yiyang Chen <chenyy23@mails.tsinghua.edu.cn>

selftests/bpf: Cover refcount acquire node offsets

This commit adds regression tests for bpf_refcount_acquire() when used
with graph-node-derived pointers. It includes both accepted cases with
normalized pointers and rejected cases with non-zero fixed offsets.

> diff --git a/tools/testing/selftests/bpf/progs/refcounted_kptr.c b/tools/testing/selftests/bpf/progs/refcounted_kptr.c
> index 61906f48025cc..7955a997316e0 100644
> --- a/tools/testing/selftests/bpf/progs/refcounted_kptr.c
> +++ b/tools/testing/selftests/bpf/progs/refcounted_kptr.c
[ ... ]
> +SEC("tc")
> +__description("refcount_acquire_list_pop_container: acquire normalized list pop")
> +__success __retval(0)
> +int refcount_acquire_list_pop_container(void *ctx)
> +{
> +	struct node_data *node, *base, *ref;
> +	struct bpf_list_node *list_node;
> +	long err;
> +
> +	node = bpf_obj_new(typeof(*node));
> +	if (!node)
> +		return -1;
> +
> +	bpf_spin_lock(&lock);
> +	err = bpf_list_push_front(&head, &node->l);
> +	if (err) {
> +		bpf_spin_unlock(&lock);
> +		bpf_obj_drop(node);

[Severity: Medium]
Does this cause a double-free and verifier rejection? 

Since bpf_list_push_front() consumes the referenced object unconditionally,
its reference ID is cleared upon return. The verifier treats the return value
as an unknown scalar and explores both branches of the error check.

Because calling bpf_obj_drop() requires an owning reference, dropping the
already-consumed node here might cause the __success test to fail loading
with a 'release kfunc expects referenced PTR_TO_BTF_ID' error.

> +		return -2;
> +	}
> +
> +	list_node = bpf_list_pop_front(&head);
> +	bpf_spin_unlock(&lock);
[ ... ]
> diff --git a/tools/testing/selftests/bpf/progs/refcounted_kptr_fail.c b/tools/testing/selftests/bpf/progs/refcounted_kptr_fail.c
> index 7247a20c0a3bf..f6cb084af16aa 100644
> --- a/tools/testing/selftests/bpf/progs/refcounted_kptr_fail.c
> +++ b/tools/testing/selftests/bpf/progs/refcounted_kptr_fail.c
[ ... ]
> +SEC("?tc")
> +__failure __msg("R1 must have zero offset when passed to bpf_refcount_acquire")
> +long refcount_acquire_list_node_offset(void *ctx)
> +{
> +	struct node_refcounted *node, *base, *ref;
> +	struct bpf_list_node *list_node;
> +	long err;
> +
> +	node = bpf_obj_new(typeof(*node));
> +	if (!node)
> +		return 1;
> +
> +	bpf_spin_lock(&lock);
> +	err = bpf_list_push_front(&head, &node->list);
> +	if (err) {
> +		bpf_spin_unlock(&lock);
> +		bpf_obj_drop(node);

[Severity: Medium]
Similarly here in refcount_acquire_list_node_offset(), does dropping the
node after bpf_list_push_front() cause the same issue?

Depending on the verifier's branch evaluation order, this double-free logic
might cause the test to fail verification for the wrong reason, which would
break the expected __msg check.

> +		return 2;
> +	}
> +
> +	list_node = bpf_list_pop_front(&head);
> +	bpf_spin_unlock(&lock);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1781852308.git.chenyy23@mails.tsinghua.edu.cn?part=2

  reply	other threads:[~2026-06-19  8:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-19  7:59 [PATCH bpf-next 0/2] bpf: Reject offset refcount acquire arguments Yiyang Chen
2026-06-19  7:59 ` [PATCH bpf-next 1/2] " Yiyang Chen
2026-06-19 19:28   ` Eduard Zingerman
2026-06-19  7:59 ` [PATCH bpf-next 2/2] selftests/bpf: Cover refcount acquire node offsets Yiyang Chen
2026-06-19  8:30   ` sashiko-bot [this message]
2026-06-19  8:47   ` bot+bpf-ci
2026-06-19 19:30   ` Eduard Zingerman
2026-06-20 15:04 ` [PATCH bpf-next v2 0/2] bpf: Reject offset refcount acquire arguments Yiyang Chen
2026-06-20 15:04   ` [PATCH bpf-next v2 1/2] " Yiyang Chen
2026-06-20 17:48     ` Alexei Starovoitov
2026-06-20 15:04   ` [PATCH bpf-next v2 2/2] selftests/bpf: Cover refcount acquire node offsets Yiyang Chen

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=20260619083059.985F21F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=chenyy23@mails.tsinghua.edu.cn \
    --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