From: Jiri Olsa <olsajiri@gmail.com>
To: sashiko-reviews@lists.linux.dev
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
bpf@vger.kernel.org, linux-mm@kvack.org,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Lorenzo Stoakes <ljs@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Federico Di Pierro <nierro92@gmail.com>
Subject: Re: [PATCHv2 bpf-next 5/8] selftests/bpf: Test user memory mmap kfuncs
Date: Wed, 4 Nov 2026 22:09:49 +0100 [thread overview]
Message-ID: <auufHZQ_hFUvH3w0@krava> (raw)
In-Reply-To: <sashiko-outbox-194794@kernel.org>
On Tue, Nov 03, 2026 at 08:05:35AM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [Medium] selftests/bpf: call to undefined get_procmap_info() in user_mem.c
> - [Medium] selftests/bpf: unresolved kfunc externs in progs/user_mem.c
> --
>
> commit c7cc5f98b3a4b4d8d168ef0934e6c41fe197849d
> Author: Jiri Olsa <jolsa@kernel.org>
>
> selftests/bpf: Test user memory mmap kfuncs
>
> This commit adds BPF selftests for bpf_user_anon_mmap and bpf_user_munmap
> invoked from a sleepable uprobe, verifying mapping permissions and
> unmapping behavior.
>
> > diff --git a/tools/testing/selftests/bpf/prog_tests/user_mem.c b/tools/testing/selftests/bpf/prog_tests/user_mem.c
> > new file mode 100644
> > index 0000000000000..f301a18437062
> > --- /dev/null
> > +++ b/tools/testing/selftests/bpf/prog_tests/user_mem.c
> > @@ -0,0 +1,112 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +
> > +#include <test_progs.h>
> > +#include <sys/mman.h>
> > +#include <sys/personality.h>
> > +#include <unistd.h>
> > +
> > +#include "user_mem.skel.h"
> > +#include "trace_helpers.h"
> > +
> > +enum {
> > + USER_MEM_MMAP = 1,
> > + USER_MEM_UNMAP,
> > +};
> > +
> > +static noinline void user_mem_trigger(void)
> > +{
> > + asm volatile ("" ::: "memory");
> > +}
> > +
> > +static bool check_user_mem_vma(void *addr, unsigned long size, const char *perms)
> > +{
> > + size_t start, end;
> > + char vma_perms[5];
> > + int err;
> > +
> > + err = get_procmap_info(addr, &start, &end, vma_perms);
> > + if (!ASSERT_OK(err, "user_mem_vma"))
> > + return false;
> > +
> > + /* VMA can be merged, so ensure it covers at least the requested range. */
> > + if (!ASSERT_GE(end - (size_t)addr, size, "vma_size"))
> > + return false;
> > +
> > + return !perms || ASSERT_STREQ(vma_perms, perms, "vma_perms");
> > +}
> > +
> > +static bool check_user_mem_unmapped(void *addr)
> > +{
> > + size_t start, end;
> > + int err;
> > +
> > + err = get_procmap_info(addr, &start, &end, NULL);
>
> [Severity: Medium]
> Where is get_procmap_info() defined? Both check_user_mem_vma() and
> check_user_mem_unmapped() call get_procmap_info(), and this file includes
> trace_helpers.h, but neither tools/testing/selftests/bpf/trace_helpers.h nor
> tools/testing/selftests/bpf/trace_helpers.c declares or defines
> get_procmap_info().
in previous patch:
selftests/bpf: Add get_procmap_info helper
>
> Because test_progs objects are compiled with -Wall -Werror, won't calling an
> undeclared and undefined get_procmap_info() cause compiling and linking
> tools/testing/selftests/bpf to fail?
>
> > diff --git a/tools/testing/selftests/bpf/progs/user_mem.c b/tools/testing/selftests/bpf/progs/user_mem.c
> > new file mode 100644
> > index 0000000000000..e3b0689f5f2a5
> > --- /dev/null
> > +++ b/tools/testing/selftests/bpf/progs/user_mem.c
> > @@ -0,0 +1,43 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +
> > +#include <vmlinux.h>
> > +#include <bpf/bpf_helpers.h>
> > +#include <bpf/bpf_tracing.h>
> > +
> > +#include "bpf_misc.h"
> > +
> > +char _license[] SEC("license") = "GPL";
> > +
> > +extern unsigned long bpf_user_anon_mmap(unsigned long len, unsigned long prot) __ksym;
> > +extern int bpf_user_munmap(unsigned long addr, unsigned long len) __ksym;
>
> [ ... ]
>
> > +SEC("uprobe.s//proc/self/exe:user_mem_trigger")
> > +int user_mem_test(struct pt_regs *ctx)
> > +{
> > + if ((bpf_get_current_pid_tgid() >> 32) != monitored_pid)
> > + return 0;
> > +
> > + switch (action) {
> > + case USER_MEM_MMAP:
> > + user_addr = bpf_user_anon_mmap(map_len, map_prot);
> > + break;
> > + case USER_MEM_UNMAP:
> > + ret = bpf_user_munmap(user_addr, map_len);
> > + break;
> > + }
>
> [Severity: Medium]
> Can user_mem__open_and_load() in test_user_mem() succeed when loading this
> program?
>
> user_mem_test() calls bpf_user_anon_mmap() and bpf_user_munmap(), which are
> declared as required __ksym externs, but neither symbol is defined or
> registered as a BPF kfunc in the kernel or bpf_testmod. Won't libbpf fail to
> resolve these kfunc BTF IDs during user_mem__open_and_load(), causing
> test_user_mem() to fail unconditionally?
defined in:
bpf: Add user memory kfuncs
jirka
next prev parent reply other threads:[~2026-11-04 21:09 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 7:59 [PATCHv2 bpf-next 0/8] bpf: Add user memory kfuncs Jiri Olsa
2026-11-03 7:59 ` [PATCHv2 bpf-next 1/8] bpf: Honor const on generic kfunc memory arguments Jiri Olsa
2026-11-03 8:52 ` bot+bpf-ci
2026-11-03 18:03 ` Alexei Starovoitov
2026-11-03 21:36 ` Jiri Olsa
2026-11-03 7:59 ` [PATCHv2 bpf-next 2/8] bpf: Add user memory kfuncs Jiri Olsa
2026-11-03 8:19 ` sashiko-bot
2026-11-03 8:52 ` bot+bpf-ci
2026-11-03 18:05 ` Alexei Starovoitov
2026-11-03 21:36 ` Jiri Olsa
2026-11-03 7:59 ` [PATCHv2 bpf-next 3/8] selftests/bpf: Add get_procmap_info helper Jiri Olsa
2026-11-03 7:59 ` [PATCHv2 bpf-next 4/8] selftests/bpf: Test const kfunc memory arguments Jiri Olsa
2026-11-03 8:10 ` sashiko-bot
2026-11-04 21:12 ` Jiri Olsa
2026-11-03 7:59 ` [PATCHv2 bpf-next 5/8] selftests/bpf: Test user memory mmap kfuncs Jiri Olsa
2026-11-03 8:05 ` sashiko-bot
2026-11-04 21:09 ` Jiri Olsa [this message]
2026-11-03 7:59 ` [PATCHv2 bpf-next 6/8] selftests/bpf: Test user memory page exec Jiri Olsa
2026-11-03 8:39 ` bot+bpf-ci
2026-11-04 21:12 ` Jiri Olsa
2026-11-03 7:59 ` [PATCHv2 bpf-next 7/8] selftests/bpf: Test bpf_copy_to_user kfunc Jiri Olsa
2026-11-03 7:59 ` [PATCHv2 bpf-next 8/8] selftests/bpf: Test user memory kfunc errors Jiri Olsa
2026-11-03 8:39 ` bot+bpf-ci
2026-11-04 21:38 ` Jiri Olsa
2026-11-03 18:08 ` [PATCHv2 bpf-next 0/8] bpf: Add user memory kfuncs Alexei Starovoitov
2026-11-03 21:36 ` Jiri Olsa
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=auufHZQ_hFUvH3w0@krava \
--to=olsajiri@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=memxor@gmail.com \
--cc=nierro92@gmail.com \
--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 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.