Skip to content

uprobes: Use percpu_rw_semaphore to fix register/unregister vs dup_mmap() race

Oleg Nesterov lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest1 patch 1 replyIn review

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/1uprobes: Use percpu_rw_semaphore to fix register/unregister vs dup_mmap() raceinclude/linux/uprobes.h kernel/events/uprobes.c kernel/fork.c+33 -31 reply

Reviews trailers per patch

The patch has a Reviewed-by or Acked-by.

PatchSrikar Dronamraju
1/1A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/1] uprobes: Use percpu_rw_semaphore to fix register/unregister vs dup_mmap() race

Hello.

The same patch I sent before, the only difference is that it uses percpu_rw_semaphore instead of brw_mutex.

Srikar, I'll hope you can ack v2 too, and unless someone objects I'll ask Ingo to pull this fix.

Tejun, recently we briefly discussed signal->group_rwsem, please see the note about cgroups below.

Note:

- The current implementation of percpu_rw_semaphore is not optimal, register/unregister will block fork() completely while it sleeps in msleep() and synchronize_sched().

So this patch assumes that

percpu_rw_semaphore-reimplement-to-not-block-the-readers-unnecessarily.patch
http://marc.info/?l=linux-mm-commits&m=135240650828875

will be applied eventually (and the new implementation can be improved).

- This patch adds percpu_down_read/up_read around dup_mmap() for uprobes.

Given that it is very cheap (and assuming the optimizations above), _perhaps_ we can turn this dup_mmap_sem into fork_sem and use it instead of threadgroup_change_begin/end, so that uprobes and cgroups can use it.

- Compared to v1, percpu_rw_semaphore doesn't support multi- writers. I hope we can tolerate this, register/unregister are system-wide and rare events anyway. And _perhaps_ we can add percpu_down_write_nonexclusive() later.

- Given that currently percpu_down_write() is exclusive, this patch almost dismisses the purpose of uprobes_mutex[] array.

Yes, but we need to rework this locking anyway for filtering.

Oleg.