Re: [PATCH v5 3/4] tracing: Use vmap_page_range() to map memmap ring buffer
From: Linus Torvalds
Date: Wed Apr 02 2025 - 13:21:30 EST
On Wed, 2 Apr 2025 at 10:13, Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
>
> /* If the buffer is not part of the normal memory, do not allow mapping */
> if (!virt_addr_valid(cpu_buffer->reader_page->page))
> return -ENODEV;
Honestly, virt_addr_valid() is pretty much random.
It's not really a valid function outside of random debugging code. It
has no real semantics. The comment saying that it validates some kind
of 'virt_to_page()' thing is pure garbage.
> As the buffer can come from anywhere, but we only allow a memory mapping to
> user space if the buffer is from the normal memory allocator.
You should damn well keep track of where the memory comes from.
You can't just say "I'll take random shit, and then I'll ask the VM what it is".
Stop it.
If the address came from something you consider trustworthy, then just
trust it. If some admin person gave you garbage, it's better to just
get a random oops than to have random bogus code.
Linus