Skip to contentSkip to conversation

uprobes-revert-ref_ctr_offset-in-uprobe_unregister-error-path.patch removed from -mm tree

merged mm-nonmm-stable Andrew Morton 1 participant 1 message Jul 10, 2025

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: uprobes: revert ref_ctr_offset in uprobe_unregister error path
has been removed from the -mm tree. Its filename was
uprobes-revert-ref_ctr_offset-in-uprobe_unregister-error-path.patch

This patch was dropped because it was merged into the mm-nonmm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Jiri Olsa <[email protected]>
Subject: uprobes: revert ref_ctr_offset in uprobe_unregister error path
Date: Wed, 14 May 2025 12:18:09 +0200

There's error path that could lead to inactive uprobe:

1) uprobe_register succeeds - updates instruction to int3 and changes ref_ctr from 0 to 1
2) uprobe_unregister fails - int3 stays in place, but ref_ctr is changed to 0 (it's not restored to 1 in the fail path) uprobe is leaked
3) another uprobe_register comes and re-uses the leaked uprobe and succeds - but int3 is already in place, so ref_ctr update is skipped and it stays 0 - uprobe CAN NOT be triggered now
4) uprobe_unregister fails because ref_ctr value is unexpected

Fix this by reverting the updated ref_ctr value back to 1 in step 2), which is the case when uprobe_unregister fails (int3 stays in place), but we have already updated refctr.

The new scenario will go as follows:

1) uprobe_register succeeds - updates instruction to int3 and changes ref_ctr from 0 to 1
2) uprobe_unregister fails - int3 stays in place and ref_ctr is reverted to 1.. uprobe is leaked
3) another uprobe_register comes and re-uses the leaked uprobe and succeds - but int3 is already in place, so ref_ctr update is skipped and it stays 1 - uprobe CAN be triggered now
4) uprobe_unregister succeeds

Fixes 1cc33161a83d ("uprobes: Support SDT markers having reference count (semaphore)")
Cc Andrii Nakryiko <[email protected]>
Cc "Masami Hiramatsu (Google)" <[email protected]>
Cc Peter Zijlstra <[email protected]>

---

 kernel/events/uprobes.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/events/uprobes.c renamed from kernel/events/uprobes.c~uprobes-revert-ref_ctr_offset-in-uprobe_unregister-error-path +2 -2
@@ -581,8 +581,8 @@ retry:
 
 out:
 	/* Revert back reference counter if instruction update failed. */
-	if (ret < 0 && is_register && ref_ctr_updated)
-		update_ref_ctr(uprobe, mm, -1);
+	if (ret < 0 && ref_ctr_updated)
+		update_ref_ctr(uprobe, mm, is_register ? -1 : 1);
 
 	/* try collapse pmd for compound page */
 	if (ret > 0)

_

Patches currently in -mm which might be from [email protected] are