Re: [PATCH 3/3] exec: Transform exec_update_mutex into a rw_semaphore

From: Davidlohr Bueso
Date: Fri Dec 04 2020 - 17:14:48 EST


On Fri, 04 Dec 2020, Linus Torvalds wrote:

On Fri, Dec 4, 2020 at 12:30 PM Bernd Edlinger
<bernd.edlinger@xxxxxxxxxx> wrote:

> perf_event_open (exec_update_mutex -> ovl_i_mutex)

Side note: this one looks like it should be easy to fix.

Is there any real reason why exec_update_mutex is actually gotten that
early, and held for that long in the perf event code?

afaict just to validate the whole operation early. Per 79c9ce57eb2 the
mutex will guard the check and the perf_install_in_context vs exec.


I _think_ we could move the ptrace check to be much later, to _just_ before that

* This is the point on no return; we cannot fail hereafter.

point in the perf event install chain..

Peter had the idea of doing the ptrace_may_access() check twice: first
lockless and early, then under exec_update_mutex when it mattered right
before perf_install_in_context():

https://lore.kernel.org/linux-fsdevel/20200828123720.GZ1362448@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/


I don't think it needs to be moved down even that much, I think it
would be sufficient to move it down below the "perf_event_alloc()",
but I didn't check very much.

Yeah we could just keep a single ptrace_may_access() check just further
down until it won't deadlock.

Thanks,
Davidlohr