mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Florent Revest" <florent.revest@linux.dev>
To: <bot+bpf-ci@kernel.org>, <bpf@vger.kernel.org>, <ast@kernel.org>,
	<daniel@iogearbox.net>, <andrii@kernel.org>
Cc: <martin.lau@linux.dev>, <eddyz87@gmail.com>, <memxor@gmail.com>,
	<song@kernel.org>, <yonghong.song@linux.dev>, <jolsa@kernel.org>,
	<kpsingh@kernel.org>, <john.fastabend@gmail.com>,
	<leon.hwang@linux.dev>, <zirajs7@gmail.com>,
	<rhkrqnwk98@gmail.com>, <puranjay@kernel.org>,
	<xukuohai@huaweicloud.com>, <iii@linux.ibm.com>,
	<hbathini@linux.ibm.com>, <chleroy@kernel.org>,
	<naveen@kernel.org>, <bjorn@kernel.org>, <pulehui@huawei.com>,
	<yangtiezhu@loongson.cn>, <hengqi.chen@gmail.com>,
	<linux-kernel@vger.kernel.org>, <martin.lau@kernel.org>,
	<eddyz87@gmail.com>, <yonghong.song@linux.dev>,
	<mason@kernel.org>, <ihor.solodrai@linux.dev>
Subject: Re: [PATCH bpf v2 2/2] selftests/bpf: Detach a trampoline prog while a task sleeps before it
Date: Tue, 15 Sep 2026 19:14:37 +0000	[thread overview]
Message-ID: <DLG4OYLUDJ69.23VI84CLNNRRU@linux.dev> (raw)
In-Reply-To: <1846328ba25c25cd5bfe44219f2836f50f90e4c5e243a40042800f67e8d5f372@mail.kernel.org>

On Sat Sep 12, 2026 at 10:53 AM UTC,  wrote:
> > diff --git a/tools/testing/selftests/bpf/prog_tests/tramp_prog_detach.c b/tools/testing/selftests/bpf/prog_tests/tramp_prog_detach.c
> > new file mode 100644
> > index 000000000000..9a0e1fc44c74
> > --- /dev/null
> > +++ b/tools/testing/selftests/bpf/prog_tests/tramp_prog_detach.c
> > @@ -0,0 +1,191 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +#include <test_progs.h>
> > +#include <pthread.h>
> > +#include <poll.h>
> > +#include <sys/mman.h>
> > +#include <sys/syscall.h>
> > +#include <linux/userfaultfd.h>
> > +#include "tramp_prog_detach.skel.h"
> > +#include "testing_helpers.h"
> > +
> > +/*
> > + * Detach and free a prog while a task sleeps in the prog that runs before it
> > + * in the same trampoline image, then let that task continue through the
> > + * image. It must not call into the freed prog.
> > + *
> > + * The task is held in a sleepable fentry prog with userfaultfd, like
> > + * bpf_mod_race does.
> > + */
>
> This isn't a bug, but does "a sleepable fentry prog" still cover both
> subtests?  serial_test_tramp_prog_detach() runs test_detach(false) and
> test_detach(true), and the second one holds the task in the prog from
> SEC("?fexit.s/bpf_fentry_test1").
>
> Would dropping "fentry" here, so it just reads "a sleepable prog", match
> what the file does now?  The per-subtest comments in
> serial_test_tramp_prog_detach() already spell out the fentry and fexit
> cases.

Sure, will say "a sleepable prog" in v3.

> > +
> > +static int test_setup_uffd(void *fault_addr)
> > +{
> > +	struct uffdio_register uffd_register = {};
> > +	struct uffdio_api uffd_api = {};
> > +	int uffd;
> > +
> > +	uffd = syscall(__NR_userfaultfd, O_CLOEXEC);
> > +	if (uffd < 0)
> > +		return -errno;
> > +
> > +	uffd_api.api = UFFD_API;
> > +	uffd_api.features = 0;
> > +	if (ioctl(uffd, UFFDIO_API, &uffd_api)) {
> > +		close(uffd);
> > +		return -1;
> > +	}
> > +
> > +	uffd_register.range.start = (unsigned long)fault_addr;
> > +	uffd_register.range.len = getpagesize();
> > +	uffd_register.mode = UFFDIO_REGISTER_MODE_MISSING;
> > +	if (ioctl(uffd, UFFDIO_REGISTER, &uffd_register)) {
> > +		close(uffd);
> > +		return -1;
> > +	}
> > +	return uffd;
> > +}
>
> This isn't a bug either, but this test_setup_uffd() looks like the
> same helper that already lives in prog_tests/bpf_mod_race.c: same
> name, same uffd_register/uffd_api/uffd locals, same UFFDIO_API then
> UFFDIO_REGISTER order, and the same close()/return -1 handling.  The
> only difference is that bpf_mod_race.c goes through its local
> sys_userfaultfd() wrapper instead of calling
> syscall(__NR_userfaultfd, O_CLOEXEC) directly.
>
> There is no shared userfaultfd helper in testing_helpers.h today, so
> the two copies would have to be kept in sync by hand.  Would it be
> worth moving it into testing_helpers.c so both tests share one copy?

Sure why not, I'll try that in v3.

      reply	other threads:[~2026-09-15 19:14 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-12  9:59 [PATCH bpf v2 0/2] bpf: Fix use-after-free of progs detached from busy trampolines Florent Revest (Anthropic)
2026-09-12  9:59 ` [PATCH bpf v2 1/2] bpf: Skip detached progs in trampoline images that are still in use Florent Revest (Anthropic)
2026-09-12 11:11   ` bot+bpf-ci
2026-09-15 19:13     ` Florent Revest
2026-09-12 16:42   ` Alexei Starovoitov
2026-09-15 18:39     ` Florent Revest
2026-09-16  5:29       ` Alexei Starovoitov
2026-09-16  7:52         ` Florent Revest
2026-09-16 18:03           ` Alexei Starovoitov
2026-09-14  4:13   ` Junseo Lim
2026-09-15 17:59     ` Florent Revest
2026-09-12  9:59 ` [PATCH bpf v2 2/2] selftests/bpf: Detach a trampoline prog while a task sleeps before it Florent Revest (Anthropic)
2026-09-12 10:53   ` bot+bpf-ci
2026-09-15 19:14     ` Florent Revest [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=DLG4OYLUDJ69.23VI84CLNNRRU@linux.dev \
    --to=florent.revest@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bjorn@kernel.org \
    --cc=bot+bpf-ci@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=chleroy@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=hbathini@linux.ibm.com \
    --cc=hengqi.chen@gmail.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=iii@linux.ibm.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=leon.hwang@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mason@kernel.org \
    --cc=memxor@gmail.com \
    --cc=naveen@kernel.org \
    --cc=pulehui@huawei.com \
    --cc=puranjay@kernel.org \
    --cc=rhkrqnwk98@gmail.com \
    --cc=song@kernel.org \
    --cc=xukuohai@huaweicloud.com \
    --cc=yangtiezhu@loongson.cn \
    --cc=yonghong.song@linux.dev \
    --cc=zirajs7@gmail.com \
    /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

all inboxes | Powered by JetHome®