Re: [PATCH v4 3.0-rc2-tip 2/22] 2: uprobes: Breakground page replacement.

Peter Zijlstra
2011-06-14T15:08:33Z

On Tue, 2011-06-14 at 16:27 +0200, Oleg Nesterov wrote:
> On 06/14, Peter Zijlstra wrote:
> >
> > On Mon, 2011-06-13 at 19:00 +0200, Oleg Nesterov wrote:
> > >
> > > Also. This is called under down_read(mmap_sem), can't we race with
> > > access_process_vm() modifying the same memory?
> >
> > Shouldn't matter COW and similar things are serialized using the pte
> > lock.
>
> Yes, but afaics this doesn't matter. Suppose that write_opcode() is
> called when access_process_vm() does copy_to_user_page(). We can cow
> the page before memcpy() completes.

access_process_vm() will end up doing a FOLL_WRITE itself when
copy_to_user_page() is called since write=1 in that case.

At that point we have a COW-race, someone wins, but the other will then
return the same page.

At this point further PTRACE pokes can indeed race with the memcpy in
write_opcode(). A possible fix would be to lock_page() around
copy_to_user_page() (its already done in set_page_dirty_lock(), so
pulling it out shouldn't matter much).