From: Mahe Tardy <mahe.tardy@gmail.com>
To: bot+bpf-ci@kernel.org
Cc: bpf@vger.kernel.org, andrew+netdev@lunn.ch, andrii@kernel.org,
ast@kernel.org, daniel@iogearbox.net, davem@davemloft.net,
eddyz87@gmail.com, edumazet@google.com, john.fastabend@gmail.com,
kuba@kernel.org, liamwisehart@meta.com, martin.lau@linux.dev,
pabeni@redhat.com, song@kernel.org, netdev@vger.kernel.org,
sdf.kernel@gmail.com, ameryhung@gmail.com, kuniyu@google.com,
memxor@gmail.com, jiayuan.chen@linux.dev, sdf@fomichev.me,
martin.lau@kernel.org, yonghong.song@linux.dev, clm@meta.com,
ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v7 5/5] selftests/bpf: Add ksock test for async callback guard
Date: Fri, 14 Aug 2026 19:02:32 +0200 [thread overview]
Message-ID: <an9KKJtU5XrastyR@gmail.com> (raw)
In-Reply-To: <62274a8d6156015b945bc8e7b5b8c2962332b104e3484a5a2d0e0b0c95b531b1@mail.kernel.org>
On Thu, Aug 13, 2026 at 12:13:31PM +0000, bot+bpf-ci@kernel.org wrote:
> > diff --git a/tools/testing/selftests/bpf/prog_tests/ksock_wq.c b/tools/testing/selftests/bpf/prog_tests/ksock_wq.c
> > new file mode 100644
> > index 0000000000000..d6dc20b8f95bb
> > --- /dev/null
> > +++ b/tools/testing/selftests/bpf/prog_tests/ksock_wq.c
> > @@ -0,0 +1,45 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/* Copyright (c) 2026 Isovalent */
> > +
> > +#include <unistd.h>
> > +
> > +#include "test_progs.h"
> > +#include "ksock_wq.skel.h"
> > +
> > +#define CALLBACK_WAIT_RETRIES 1000
> > +#define CALLBACK_WAIT_US 1000
> > +
> > +void test_ksock_wq(void)
>
> This commit adds a new standalone test file for the workqueue guard check.
> The same directory already has prog_tests/ksock.c (from commit a529f8c4d088b
> two patches earlier in this series) which is the home of the ksock kfunc
> tests. Notably, the immediately preceding commit in this series
> (75ef545fdff15) added its negative test as a new function inside the
> existing prog_tests/ksock.c rather than creating a new file. A subsystem
> pattern flags this as potentially concerning: should test_ksock_wq() be
> another function/subtest in prog_tests/ksock.c, consistent with how patch
> 4 of this same series added its case? The split means the ksock feature's
> tests are now across two files with generated test names 'ksock_lsm',
> 'ksock_lsm_verifier' and 'ksock_wq' rather than grouped together.
Yes indeed this one was added in a separate file, not sure it's
important.
>
> > +{
> > + LIBBPF_OPTS(bpf_test_run_opts, opts);
> > + struct ksock_wq *skel;
> > + u32 callback_done;
> > + int err, i;
> > +
> > + skel = ksock_wq__open_and_load();
> > + if (!ASSERT_OK_PTR(skel, "ksock_wq open and load"))
> > + return;
> > +
> > + err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.ksock_wq_start),
> > + &opts);
> > + if (!ASSERT_OK(err, "run ksock_wq_start"))
> > + goto out;
> > + if (!ASSERT_OK(opts.retval, "ksock_wq_start retval"))
> > + goto out;
> > +
> > + for (i = 0; i < CALLBACK_WAIT_RETRIES; i++) {
> > + if (__atomic_load_n(&skel->bss->callback_done, __ATOMIC_ACQUIRE))
> > + break;
> > + usleep(CALLBACK_WAIT_US);
> > + }
> > + callback_done = __atomic_load_n(&skel->bss->callback_done,
> > + __ATOMIC_ACQUIRE);
> > + if (!ASSERT_EQ(callback_done, 1, "workqueue callback completed"))
> > + goto out;
> > +
> > + ASSERT_EQ(skel->bss->create_err, -EOPNOTSUPP,
> > + "workqueue create rejected");
> > +
> > +out:
> > + ksock_wq__destroy(skel);
> > +}
> > diff --git a/tools/testing/selftests/bpf/progs/ksock_wq.c b/tools/testing/selftests/bpf/progs/ksock_wq.c
> > new file mode 100644
> > index 0000000000000..16a1873d132ed
> > --- /dev/null
> > +++ b/tools/testing/selftests/bpf/progs/ksock_wq.c
> > @@ -0,0 +1,62 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/* Copyright (c) 2026 Isovalent */
> > +
> > +#include "vmlinux.h"
> > +#include <bpf/bpf_helpers.h>
> > +#include "bpf_experimental.h"
> > +#include "bpf_tracing_net.h"
> > +#include "errno.h"
> > +#include "ksock_common.h"
> > +
> > +struct ksock_wq_value {
> > + struct bpf_wq work;
> > +};
> > +
> > +struct {
> > + __uint(type, BPF_MAP_TYPE_ARRAY);
> > + __uint(max_entries, 1);
> > + __type(key, u32);
> > + __type(value, struct ksock_wq_value);
> > +} work_map SEC(".maps");
> > +
> > +int create_err;
> > +u32 callback_done;
> > +
> > +static int ksock_wq_callback(void *map, int *key, void *value)
> > +{
> > + struct bpf_ksock_create_opts opts = {
> > + .family = AF_INET,
> > + .type = SOCK_DGRAM,
> > + .protocol = IPPROTO_UDP,
> > + };
> > + struct bpf_ksock *ks;
> > + int err = 0;
> > +
> > + ks = bpf_ksock_create(&opts, sizeof(opts), &err);
> > + if (ks)
> > + bpf_ksock_release(ks);
> > + create_err = err;
> > + __sync_fetch_and_add(&callback_done, 1);
> > + return 0;
> > +}
>
> [ ... ]
>
> > selftests/bpf: Add ksock test for async callback guard
> >
> > Because the kfuncs are going through LSM hooks, allowing their use via
> > workqueue callbacks would expose the wrong credentials. This test
> > ensures the kfunc are preventing any use from these contexts.
>
> This isn't a bug, but the changelog says the test "ensures the kfunc are
> preventing any use from these contexts", which reads as covering the
> whole kfunc set. The added program exercises exactly one kfunc from the
> workqueue callback, bpf_ksock_create(). The other two kfuncs that carry
> the same runtime guard, bpf_ksock_connect() and bpf_ksock_send(), are not
> exercised from an async callback anywhere in the tree. Would it be worth
> either narrowing the changelog to say the test covers bpf_ksock_create(),
> or extending the callback to also call bpf_ksock_send() on a stashed kptr
> so all three guarded kfuncs are pinned?
Yeah, eventually they all call bpf_ksock_has_user_task_context() so the
runtime guard tested is the same.
>
>
> ---
> AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
> See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
>
> CI run summary: https://github.com/kernel-patches/bpf/actions/runs/31694719067
prev parent reply other threads:[~2026-08-14 17:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 11:05 [PATCH bpf-next v7 0/5] Introduce bpf_ksock Mahe Tardy
2026-08-13 11:05 ` [PATCH bpf-next v7 1/5] net: Add connect_socket() helper Mahe Tardy
2026-08-13 11:05 ` [PATCH bpf-next v7 2/5] bpf: Add ksock kfuncs Mahe Tardy
2026-08-13 11:05 ` [PATCH bpf-next v7 3/5] selftests/bpf: Add ksock kfunc test Mahe Tardy
2026-08-13 12:13 ` bot+bpf-ci
2026-08-14 16:59 ` Mahe Tardy
2026-08-13 11:05 ` [PATCH bpf-next v7 4/5] selftests/bpf: Test forbidden bpf_ksock_send() LSM attach Mahe Tardy
2026-08-13 11:05 ` [PATCH bpf-next v7 5/5] selftests/bpf: Add ksock test for async callback guard Mahe Tardy
2026-08-13 12:13 ` bot+bpf-ci
2026-08-14 17:02 ` Mahe Tardy [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=an9KKJtU5XrastyR@gmail.com \
--to=mahe.tardy@gmail.com \
--cc=ameryhung@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=clm@meta.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@google.com \
--cc=ihor.solodrai@linux.dev \
--cc=jiayuan.chen@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=liamwisehart@meta.com \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf.kernel@gmail.com \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=yonghong.song@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