Re: [PATCH -next v1 3/3] kernel/events/uprobes: uprobe_write_opcode() rewrite

From: Oleg Nesterov
Date: Tue Mar 11 2025 - 08:37:09 EST


On 03/11, David Hildenbrand wrote:
>
> Regarding both questions, the code is fairly racy. Nothing would stop user
> space from (a) modifying that memory

Yes, but we don't really care. uprobes.c assumes that user-space won't play
with the probed memory.

Note that if is_register is false, then vma can be even writable. Hmm, why?
Perhaps valid_vma() should ignore is_register and nack VM_MAYWRITE ? But
this doesn't really matter, say, gdb can change this memory anyway. Again,
we don't really care.

> >do something like
> >
> > /* Walk the page tables again, to perform the actual update. */
> > ret = -EAGAIN;
> > folio = folio_walk_start(&fw, vma, vaddr, 0);
> > if (folio) {
> > if (fw.page == page) {
> > WARN_ON(is_register && !folio_test_anon(folio));
>
> Yes, that would work (we could leave the WARN_ON in __uprobe_write_opcode),
> but I am not sure if the end result is better better. No strong opinion on
> the details though.

Will, this way __uprobe_write_opcode() will look a little bit simpler...

But I won't insist, please do what you think is better.

Oleg.