From: sashiko-bot@kernel.org
To: "Jiri Olsa" <jolsa@kernel.org>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>
Cc: 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 2/8] bpf: Add user memory kfuncs
Date: Tue, 03 Nov 2026 08:19:54 +0000 [thread overview]
Message-ID: <sashiko-outbox-194818@kernel.org> (raw)
In-Reply-To: <20261103075916.100050-3-jolsa@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] bpf: bpf_user_vm_mmap() clears active TS_COMPAT on TIF_ADDR32 tasks
- [Medium] bpf: bpf_user_vm_mmap() triggers false in_32bit_syscall() on x86_64
--
commit f91c9a5c8eeb0a10c48d0c7030bd2cd248f6d3fd
Author: Jiri Olsa <jolsa@kernel.org>
bpf: Add user memory kfuncs
This commit adds the sleepable kfuncs bpf_copy_to_user(),
bpf_user_anon_mmap(), and bpf_user_munmap() for KPROBE BPF programs to
modify a user task's address space and manage private anonymous mappings.
> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> index 58e357302850e..ae7dfa58ae95c 100644
> --- a/kernel/bpf/helpers.c
> +++ b/kernel/bpf/helpers.c
[ ... ]
> @@ -3741,6 +3747,110 @@ __bpf_kfunc int bpf_copy_from_user_mm(void *dst, u32 dst__sz,
[ ... ]
> +/* bpf_wq and bpf_task_work callbacks can run without a usable mm. */
> +static bool bpf_user_mm_ok(void)
> +{
> + return current->mm && !(current->flags & (PF_KTHREAD | PF_EXITING));
> +}
> +
> +#ifdef CONFIG_IA32_EMULATION
> +static unsigned long bpf_user_vm_mmap(unsigned long len, unsigned long prot)
> +{
> + struct thread_info *ti = current_thread_info();
> + bool compat = test_thread_flag(TIF_ADDR32);
> + unsigned long addr;
> +
> + /*
> + * We are not in a syscall, but x86 get_unmapped_area() paths
> + * ignore TIF_ADDR32 and rely on in_32bit_syscall().
> + */
> + if (compat)
> + ti->status |= TS_COMPAT;
> + addr = vm_mmap(NULL, 0, len, prot, MAP_PRIVATE | MAP_ANONYMOUS, 0);
[Severity: Medium]
As reported by bot+bpf-ci@kernel.org on v1 [1], on x86_64 kernels with
CONFIG_X86_X32_ABI=y, will calling bpf_user_anon_mmap() from a sleepable
uprobe in a native 64-bit process falsely trigger in_32bit_syscall() and
restrict mappings to the 32-bit compat range below 4 GiB?
When a 64-bit task enters a uprobe breakpoint exception (or sys_uprobe /
sys_uretprobe), task_pt_regs(current)->orig_ax is -1. Under
CONFIG_X86_X32_ABI=y, in_32bit_syscall() checks in_x32_syscall():
arch/x86/include/asm/compat.h:in_x32_syscall() {
#ifdef CONFIG_X86_X32_ABI
if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)
return true;
#endif
return false;
}
Because bpf_user_vm_mmap() passes addr = 0 to vm_mmap(),
arch_get_unmapped_area_topdown() and arch_get_unmapped_area() call
get_mmap_base() and find_start_end(), which both check in_32bit_syscall()
and select mm->mmap_compat_base and task_size_32bit() instead of the 64-bit
address space.
> + if (compat)
> + ti->status &= ~TS_COMPAT;
[Severity: Medium]
Could clearing TS_COMPAT unconditionally whenever TIF_ADDR32 is set clobber
an active 32-bit syscall's TS_COMPAT state?
When a 32-bit IA32 task enters a syscall via syscall_32_enter(), TS_COMPAT
is set in current_thread_info()->status and must remain set until
arch_exit_to_user_mode_prepare() clears it after signal handling and
syscall restart fixups:
arch/x86/include/asm/entry-common.h:arch_exit_to_user_mode_prepare() {
...
/*
* Compat syscalls set TS_COMPAT. Make sure we clear it before
* returning to user mode. We need to clear it *after* signal
* handling, because syscall restart has a fixup for compat
* syscalls. The fixup is exercised by the ptrace_syscall_32
* selftest.
...
*/
current_thread_info()->status &= ~(TS_COMPAT | TS_I386_REGS_POKED);
}
If a kprobe schedules a sleepable bpf_task_work callback that runs during
syscall exit (for example via task_work_run() inside get_signal() or
ptrace_notify()) and calls bpf_user_anon_mmap() -> bpf_user_vm_mmap(),
ti->status &= ~TS_COMPAT will clear TS_COMPAT before signal handling
finishes. Subsequent calls to syscall_get_error(), in_ia32_syscall(), and
in_compat_syscall() will then treat the active 32-bit syscall as a 64-bit
syscall.
Should bpf_user_vm_mmap() only set and clear TS_COMPAT when
!(ti->status & TS_COMPAT)?
[1] https://lore.kernel.org/r/571f32a410a85199bc9bcecfe07a9a9b6ef425b2052643e64031dd246c13691e@mail.kernel.org
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261103075916.100050-1-jolsa@kernel.org?part=1
next prev parent reply other threads:[~2026-11-03 8:20 UTC|newest]
Thread overview: 22+ 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 [this message]
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-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-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-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-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=sashiko-outbox-194818@kernel.org \
--to=sashiko-bot@kernel.org \
--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=jolsa@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox