[PATCH v7 3/6] Uprobes: Support SDT markers having reference count (semaphore)

From
Oleg Nesterov <oleg@redhat.com>
Date
2018-08-07 11:36:31
Also in
linux-mips, lkml
Reply to
Ravi Bangoria, 2018-08-06
Hi Ravi,

On 08/06, Ravi Bangoria wrote:
quoted
quoted
+static int delayed_uprobe_add(struct uprobe *uprobe, struct mm_struct *mm)
+{
+	struct delayed_uprobe *du;
+
+	if (delayed_uprobe_check(uprobe, mm))
+		return 0;
+
+	du  = kzalloc(sizeof(*du), GFP_KERNEL);
+	if (!du)
+		return -ENOMEM;
+
+	du->uprobe = uprobe;
+	du->mm = mm;
I am surprised I didn't notice this before...

So
	du->mm = mm;

is fine, mm can't go away, uprobe_clear_state() does delayed_uprobe_remove(NULL,mm).

But
	du->uprobe = uprobe;

doesn't look right, uprobe can go away and it can be freed, its memory can be reused.
We can't rely on remove_breakpoint(),

I'm sorry. I didn't get this. How can uprobe go away without calling
    uprobe_unregister()
    -> rergister_for_each_vma()
       -> remove_breakpoint()
And remove_breakpoint() will get called
assuming that _unregister() will find the same vma with the probed insn. But
as I said, the application can munmap the probed page/vma.

No?
quoted
Also. delayed_uprobe_add() should check the list and avoid duplicates. Otherwise the
trivial

	for (;;)
		munmap(mmap(uprobed_file));

will eat the memory until uprobe is unregistered.

I'm already calling delayed_uprobe_check(uprobe, mm) from delayed_uprobe_add().
Oops ;)

Oleg.
Thread (11 messages) 11 messages, 2 authors, last reply 2018-08-07
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help