From: Peter Zijlstra <peterz@infradead.org>
To: "Eddy_Wu@trendmicro.com" <Eddy_Wu@trendmicro.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 19/23] kprobes: Remove kretprobe hash
Date: Fri, 28 Aug 2020 22:29:12 +0200 [thread overview]
Message-ID: <20200828202912.GA29142@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <305dad6efa9e4c42b13b72a5f770b933@trendmicro.com>
On Fri, Aug 28, 2020 at 07:32:11PM +0000, Eddy_Wu@trendmicro.com wrote:
>
> > -----Original Message-----
> > From: Masami Hiramatsu <mhiramat@kernel.org>
> >
> > @@ -1311,24 +1257,23 @@ void kprobe_busy_end(void)
> > void kprobe_flush_task(struct task_struct *tk)
> > {
> > struct kretprobe_instance *ri;
> > + struct llist_node *node;
> >
> > + /* Early boot, not yet initialized. */
> > if (unlikely(!kprobes_initialized))
> > return;
> >
> > kprobe_busy_begin();
> >
> > + node = current->kretprobe_instances.first;
> > + current->kretprobe_instances.first = NULL;
>
> I think we are flushing tk instead of current here.
> After fixing this to tk, the NULL pointer deference is gone!
Ah, very good! I can indeed confirm that that cures things.
---
Index: linux-2.6/kernel/kprobes.c
===================================================================
--- linux-2.6.orig/kernel/kprobes.c
+++ linux-2.6/kernel/kprobes.c
@@ -1275,9 +1275,7 @@ void kprobe_flush_task(struct task_struc
kprobe_busy_begin();
- node = current->kretprobe_instances.first;
- current->kretprobe_instances.first = NULL;
-
+ node == __llist_del_all(&tk->kretprobe_instances);
while (node) {
ri = container_of(node, struct kretprobe_instance, llist);
node = node->next;
@@ -1871,6 +1869,7 @@ unsigned long __kretprobe_trampoline_han
struct llist_node *first, *node;
struct kretprobe *rp;
+ /* Find all nodes for this frame. */
first = node = current->kretprobe_instances.first;
while (node) {
ri = container_of(node, struct kretprobe_instance, llist);
@@ -1900,7 +1899,7 @@ unsigned long __kretprobe_trampoline_han
while (first) {
ri = container_of(first, struct kretprobe_instance, llist);
rp = get_kretprobe(ri);
- node = first->next;
+ first = first->next;
if (rp && rp->handler) {
__this_cpu_write(current_kprobe, &rp->kp);
@@ -1910,8 +1909,6 @@ unsigned long __kretprobe_trampoline_han
}
recycle_rp_inst(ri);
-
- first = node;
}
return (unsigned long)correct_ret_addr;
Index: linux-2.6/include/linux/llist.h
===================================================================
--- linux-2.6.orig/include/linux/llist.h
+++ linux-2.6/include/linux/llist.h
@@ -237,6 +237,14 @@ static inline struct llist_node *llist_d
return xchg(&head->first, NULL);
}
+static inline struct llist_node *__llist_del_all(struct llist_head *head)
+{
+ struct llist_node *first = head->first;
+
+ head->first = NULL;
+ return first;
+}
+
extern struct llist_node *llist_del_first(struct llist_head *head);
struct llist_node *llist_reverse_order(struct llist_node *head);
next prev parent reply other threads:[~2020-08-28 20:29 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-28 12:26 [PATCH v4 00/23] kprobes: Unify kretprobe trampoline handlers and make kretprobe lockless Masami Hiramatsu
2020-08-28 12:26 ` [PATCH v4 01/23] kprobes: Add generic kretprobe trampoline handler Masami Hiramatsu
2020-08-28 12:27 ` [PATCH v4 02/23] x86/kprobes: Use " Masami Hiramatsu
2020-08-28 12:27 ` [PATCH v4 03/23] arm: kprobes: " Masami Hiramatsu
2020-08-28 12:27 ` [PATCH v4 04/23] arm64: " Masami Hiramatsu
2020-08-28 13:31 ` Mark Rutland
2020-08-28 13:37 ` peterz
2020-08-28 13:48 ` Mark Rutland
2020-08-28 13:58 ` Masami Hiramatsu
2020-08-28 12:27 ` [PATCH v4 05/23] arc: " Masami Hiramatsu
2020-08-28 12:27 ` [PATCH v4 06/23] csky: " Masami Hiramatsu
2020-08-28 12:27 ` [PATCH v4 07/23] ia64: " Masami Hiramatsu
2020-08-28 12:28 ` [PATCH v4 08/23] mips: " Masami Hiramatsu
2020-08-28 12:28 ` [PATCH v4 09/23] parisc: " Masami Hiramatsu
2020-08-28 12:28 ` [PATCH v4 10/23] powerpc: " Masami Hiramatsu
2020-08-28 12:28 ` [PATCH v4 11/23] s390: " Masami Hiramatsu
2020-08-28 12:28 ` [PATCH v4 12/23] sh: " Masami Hiramatsu
2020-08-28 12:29 ` [PATCH v4 13/23] sparc: " Masami Hiramatsu
2020-08-28 12:29 ` [PATCH v4 14/23] kprobes: Remove NMI context check Masami Hiramatsu
2020-08-28 12:29 ` [PATCH v4 15/23] kprobes: Free kretprobe_instance with rcu callback Masami Hiramatsu
2020-08-28 12:29 ` [PATCH v4 16/23] kprobes: Make local used functions static Masami Hiramatsu
2020-08-28 12:29 ` [PATCH v4 17/23] llist: Add nonatomic __llist_add() Masami Hiramatsu
2020-08-28 12:29 ` [PATCH v4 18/23] sched: Fix try_invoke_on_locked_down_task() semantics Masami Hiramatsu
2020-08-29 2:01 ` Masami Hiramatsu
2020-08-29 7:30 ` peterz
2020-08-29 17:31 ` Paul E. McKenney
2020-08-28 12:30 ` [PATCH v4 19/23] kprobes: Remove kretprobe hash Masami Hiramatsu
2020-08-28 18:37 ` Masami Hiramatsu
2020-08-28 19:02 ` peterz
2020-08-28 19:32 ` Eddy_Wu
2020-08-28 20:29 ` Peter Zijlstra [this message]
2020-08-29 1:23 ` Masami Hiramatsu
2020-08-28 12:30 ` [PATCH v4 20/23] [RFC] kprobes: Remove task scan for updating kretprobe_instance Masami Hiramatsu
2020-08-28 12:52 ` peterz
2020-08-28 15:10 ` Masami Hiramatsu
2020-08-28 15:18 ` peterz
2020-08-28 16:01 ` Masami Hiramatsu
2020-08-28 12:30 ` [PATCH v4 21/23] asm-generic/atomic: Add try_cmpxchg() fallbacks Masami Hiramatsu
2020-08-28 12:30 ` [PATCH v4 22/23] freelist: Lock less freelist Masami Hiramatsu
2020-08-28 12:30 ` [PATCH v4 23/23] kprobes: Replace rp->free_instance with freelist Masami Hiramatsu
2020-08-28 12:37 ` [PATCH v4 00/23] kprobes: Unify kretprobe trampoline handlers and make kretprobe lockless Masami Hiramatsu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200828202912.GA29142@worktop.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=Eddy_Wu@trendmicro.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).