All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yafang Shao" <laoar.shao@gmail.com>
Cc: bpf@vger.kernel.org, mkoutny@suse.com, hannes@cmpxchg.org, tj@kernel.org
Subject: Re: [RFC PATCH v2 3/3] selftests/bpf: add tests for the bpf_numab_ops struct_ops
Date: Mon, 12 Oct 2026 12:13:18 +0000	[thread overview]
Message-ID: <sashiko-outbox-168072@kernel.org> (raw)
In-Reply-To: <20261012120438.52849-4-laoar.shao@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] selftests/bpf: uninitialized skel pointer dereference on test_hierarchy error path
- [Medium] selftests/bpf: race condition leading to flaky test in test_attach_detach
--

commit 0d0b1887ad5f6f3d52adb583711d13aa30078932
Author: Yafang Shao <laoar.shao@gmail.com>

selftests/bpf: add tests for the bpf_numab_ops struct_ops

This commit adds selftests for the bpf_numab_ops struct_ops. It covers five
scenarios including attach/detach behavior, hierarchy aggregation, multi-policy
combination, inheritance, and surface-dispatching.

> diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_numab_ops.c b/tools/testing/selftests/bpf/prog_tests/bpf_numab_ops.c
> new file mode 100644
> index 0000000000000..3e5dac8e31313
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/bpf_numab_ops.c

[ ... ]

> +static void test_attach_detach(void)
> +{

[ ... ]

> +	/*
> +	 * Detach and let a grace period pass so that no reader is still
> +	 * walking the old effective array, then verify the hook stopped
> +	 * running.
> +	 */
> +	before = skel->bss->enable_cnt;
> +	bpf_link__destroy(link);
> +	link = NULL;
> +	sleep(1);
> +	burn_cpu_ms(300);
> +	ASSERT_EQ(skel->bss->enable_cnt, before, "enable_cnt_after_detach");

[Severity: Medium]
Could this snapshot timing cause the test to be flaky?

Because the task is running during bpf_link__destroy() and BPF hooks are
attached via RCU, scheduler ticks can still trigger the hook and increment
the counter after the before snapshot is taken but before the detachment is
complete or during the grace period.

If any ticks hit the task during teardown, the counts will not match and the
test will spuriously fail. Should the baseline counter be snapshotted after
the link is destroyed and the RCU grace period (sleep(1)) has fully elapsed?

[ ... ]

> +static void test_hierarchy(void)
> +{
> +	struct bpf_numab_ops *skel;
> +	struct bpf_link *plink = NULL;
> +	int parent_fd, child_fd = -1;
> +
> +	parent_fd = test__join_cgroup(CGROUP_PATH);
> +	if (!ASSERT_GE(parent_fd, 0, "join_parent_cgroup"))
> +		return;
> +
> +	child_fd = create_and_get_cgroup(CHILD_PATH);
> +	if (!ASSERT_GE(child_fd, 0, "create_child_cgroup"))
> +		goto cleanup;
> +
> +	if (!ASSERT_OK(join_cgroup(CHILD_PATH), "join_child_cgroup"))
> +		goto cleanup;
> +
> +	skel = bpf_numab_ops__open_and_load();

[ ... ]

> +cleanup:
> +	bpf_link__destroy(plink);
> +	bpf_numab_ops__destroy(skel);

[Severity: High]
Does this code dereference an uninitialized pointer if cgroup creation fails?

The skel pointer is declared without initialization. If either
create_and_get_cgroup() or join_cgroup() fails, the code jumps to the cleanup
label before skel is assigned a value.

At the cleanup label, bpf_numab_ops__destroy(skel) is invoked with the
uninitialized skel pointer containing garbage stack data. This bypasses the
internal NULL check in the destructor and can cause a segmentation fault.

Would initializing struct bpf_numab_ops *skel = NULL; prevent this?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261012120438.52849-1-laoar.shao@gmail.com?part=3

  reply	other threads:[~2026-10-12 12:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 12:04 [RFC PATCH v2 0/3] BPF-based per-cgroup NUMA balancing mode selection Yafang Shao
2026-10-12 12:04 ` [RFC PATCH v2 1/3] sched: add helpers for numa balancing Yafang Shao
2026-10-12 12:19   ` sashiko-bot
2026-10-12 14:23     ` Yafang Shao
2026-10-13  7:38   ` David Hildenbrand (Arm)
2026-10-13  9:14     ` Yafang Shao
2026-10-12 12:04 ` [RFC PATCH v2 2/3] sched: add per-cgroup NUMA balancing mode selection via BPF Yafang Shao
2026-10-12 12:25   ` sashiko-bot
2026-10-12 13:55     ` Yafang Shao
2026-10-12 12:04 ` [RFC PATCH v2 3/3] selftests/bpf: add tests for the bpf_numab_ops struct_ops Yafang Shao
2026-10-12 12:13   ` sashiko-bot [this message]
2026-10-12 17:51 ` [RFC PATCH v2 0/3] BPF-based per-cgroup NUMA balancing mode selection Tejun Heo
2026-10-13  2:16   ` Yafang Shao
2026-10-13 18:02     ` Tejun Heo
2026-10-13 15:49 ` Gregory Price

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=sashiko-outbox-168072@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=laoar.shao@gmail.com \
    --cc=mkoutny@suse.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tj@kernel.org \
    /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.