BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Paul Houssel" <paulhoussel2@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH 2/2] selftests/bpf: add tests to verify the enforcement of CONFIG_CGROUP_LSM_NUM
Date: Wed, 06 May 2026 18:41:32 +0000	[thread overview]
Message-ID: <20260506184133.70D37C2BCB8@smtp.kernel.org> (raw)
In-Reply-To: <20260506065048.592474-3-paulhoussel2@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] Resource leak (Memory & File Descriptors) in test loop.
- [Medium] Missing verification of the actual rejection error code.
- [Medium] Test flakiness due to concurrent execution consuming global limits.
--

commit 643ce21be8f485f762f000339f8443301983ef08
Author: Paul Houssel <paulhoussel2@gmail.com>

selftests/bpf: add tests to verify the enforcement of CONFIG_CGROUP_LSM_NUM
    
Add a selftest that verifies the kernel correctly enforces
CONFIG_CGROUP_LSM_NUM as the maximum number of concurrently attachable
per-cgroup LSM hook slots.

> diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_lsm_num.c b/tools/testing/selftests/bpf/prog_tests/cgroup_lsm_num.c
> new file mode 100644
> index 0000000000000..1c5825c6c3d07
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/cgroup_lsm_num.c
[ ... ]
> +void test_cgroup_lsm_num(void)

Should this test be forced to run sequentially by naming it
serial_test_cgroup_lsm_num()?

Since the kernel limits the maximum number of distinct, concurrently
attachable per-cgroup LSM hooks globally based on CONFIG_CGROUP_LSM_NUM,
if this test runs in parallel with other tests that attach to lsm_cgroup
hooks, could they exhaust the global limit and cause this test to fail
unpredictably?

> +{
> +	struct cgroup_lsm_num *skel = NULL;
> +	struct bpf_program *prog;
> +	int cgroup_fd = -1;
> +	int attached = 0;
> +	int failed = 0;
[ ... ]
> +	bpf_object__for_each_program(prog, skel->obj) {
> +		struct bpf_link *link;
> +
> +		link = bpf_program__attach_cgroup(prog, cgroup_fd);
> +		if (!link) {
> +			if (errno == EOPNOTSUPP) {
> +				test__skip();
> +				goto out;
> +			}
> +			failed++;

When we expect attachment to fail because the slot limit is exhausted,
shouldn't we also check that the error code is exactly what we expect
(such as -E2BIG)?

If the attachment fails for an unrelated reason, the failure counter still
increments, which could obscure the true root cause.

> +		} else {
> +			attached++;
> +		}

Does this code leak the link memory and its file descriptor?

Since the attachment is done manually via bpf_program__attach_cgroup()
instead of using the skeleton's auto-attach method,
cgroup_lsm_num__destroy(skel) will not automatically clean up these links.

Should we store the returned link pointer and explicitly call
bpf_link__destroy() on it to prevent exhausting the file descriptor limit
during a test run?

> +	}
> +
> +	// CONFIG_CGROUP_LSM_NUM set to 10
> +	// -> 10 programs shall be attached
> +	ASSERT_EQ(attached, 10, "at least one attached");
> +	// -> 2 programs shall be rejected
> +	ASSERT_EQ(failed, 2, "limit was enforced");
> +
> +out:
> +	close(cgroup_fd);
> +	cgroup_lsm_num__destroy(skel);
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260506065048.592474-1-paulhoussel2@gmail.com?part=2

      parent reply	other threads:[~2026-05-06 18:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-06  6:50 [PATCH 0/2] Introduce CONFIG_CGROUP_LSM_NUM to render BPF_LSM_CGROUP attachment limit configurable Paul Houssel
2026-05-06  6:50 ` [PATCH 1/2] bpf: render CGROUP_LSM_NUM configurable as a KConfig Paul Houssel
2026-05-06 12:29   ` Paul Chaignon
2026-05-06  6:50 ` [PATCH 2/2] selftests/bpf: add tests to verify the enforcement of CONFIG_CGROUP_LSM_NUM Paul Houssel
2026-05-06 13:15   ` Paul Chaignon
2026-05-06 13:25     ` polo
2026-05-06 18:41   ` sashiko-bot [this message]

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=20260506184133.70D37C2BCB8@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=paulhoussel2@gmail.com \
    --cc=sashiko@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