Skip to content

Commit f8c8572

Browse files
anakryikoIngo Molnar
authored andcommitted
uprobes: Remove too strict lockdep_assert() condition in hprobe_expire()
hprobe_expire() is used to atomically switch pending uretprobe instance (struct return_instance) from being SRCU protected to be refcounted. This can be done from background timer thread, or synchronously within current thread when task is forked. In the former case, return_instance has to be protected through RCU read lock, and that's what hprobe_expire() used to check with lockdep_assert(rcu_read_lock_held()). But in the latter case (hprobe_expire() called from dup_utask()) there is no RCU lock being held, and it's both unnecessary and incovenient. Inconvenient due to the intervening memory allocations inside dup_return_instance()'s loop. Unnecessary because dup_utask() is called synchronously in current thread, and no uretprobe can run at that point, so return_instance can't be freed either. So drop rcu_read_lock_held() condition, and expand corresponding comment to explain necessary lifetime guarantees. lockdep_assert()-detected issue is a false positive. Fixes: dd1a756 ("uprobes: SRCU-protect uretprobe lifetime (with timeout)") Reported-by: Breno Leitao <leitao@debian.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20250225223214.2970740-1-andrii@kernel.org
1 parent 68a9b0e commit f8c8572

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

kernel/events/uprobes.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -767,10 +767,14 @@ static struct uprobe *hprobe_expire(struct hprobe *hprobe, bool get)
767767
enum hprobe_state hstate;
768768

769769
/*
770-
* return_instance's hprobe is protected by RCU.
771-
* Underlying uprobe is itself protected from reuse by SRCU.
770+
* Caller should guarantee that return_instance is not going to be
771+
* freed from under us. This can be achieved either through holding
772+
* rcu_read_lock() or by owning return_instance in the first place.
773+
*
774+
* Underlying uprobe is itself protected from reuse by SRCU, so ensure
775+
* SRCU lock is held properly.
772776
*/
773-
lockdep_assert(rcu_read_lock_held() && srcu_read_lock_held(&uretprobes_srcu));
777+
lockdep_assert(srcu_read_lock_held(&uretprobes_srcu));
774778

775779
hstate = READ_ONCE(hprobe->state);
776780
switch (hstate) {

0 commit comments

Comments
 (0)