kprobes: fix race in aggregate kprobe registration
PATCH 1/1 kprobes: fix race in aggregate kprobe registration
From: Ananth N Mavinakayanahalli <[email protected]>
When registering multiple kprobes at the same address, we leave a small window where the kprobe hlist will not contain a reference to the registered kprobe, leading to potentially, a system crash if the breakpoint is hit on another processor.
Patch below changes the order of hlist updation to make sure that there is always a reference to the kprobe at the location.
---
kernel/kprobes.c | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-)
kernel/kprobes.c +1 -1
@@ -400,9 +400,9 @@ static inline void add_aggr_kprobe(struclist_add_rcu (&p->list, &ap->list);INIT_HLIST_NODE (&ap->hlist); -hlist_del_rcu (&p->hlist);hlist_add_head_rcu (&ap->hlist, &kprobe_table[hash_ptr (ap->addr,KPROBE_HASH_BITS )]); +hlist_del_rcu (&p->hlist); }/*
Quoted 9 lines · Ananth N Mavinakayanahalli
From: Ananth N Mavinakayanahalli <[email protected]>
When registering multiple kprobes at the same address, we leave a small window where the kprobe hlist will not contain a reference to the registered kprobe, leading to potentially, a system crash if the breakpoint is hit on another processor.
Patch below changes the order of hlist updation to make sure that there is always a reference to the kprobe at the location.
Hi Ananth,
How do you like this patch? Here the old entry
will be replace with the new entry automically.
kernel/kprobes.c | 5 +---- 1 files changed, 1 insertion(+), 4 deletions(-)
kernel/kprobes.c +1 -4
@@ -399,10 +399,7 @@ static inline void add_aggr_kprobe(strucINIT_LIST_HEAD (&ap->list);list_add_rcu (&p->list, &ap->list); -INIT_HLIST_NODE (&ap->hlist); -hlist_del_rcu (&p->hlist); -hlist_add_head_rcu (&ap->hlist, - &kprobe_table[hash_ptr (ap->addr,KPROBE_HASH_BITS )]); +hlist_replace_rcu (&p->hlist, &ap->hlist); }/*
Ananth N Mavinakayanahalli
Acked-byQuoted 8 lines · Keshavamurthy Anil S
Quoted 7 lines · Ananth N Mavinakayanahalli
From: Ananth N Mavinakayanahalli <[email protected]>
When registering multiple kprobes at the same address, we leave a small window where the kprobe hlist will not contain a reference to the registered kprobe, leading to potentially, a system crash if the breakpoint is hit on another processor.
Quoted 6 lines
Quoted 2 lines
Patch below changes the order of hlist updation to make sure that there is always a reference to the kprobe at the location.
Hi Ananth,
How do you like this patch? Here the old entry
will be replace with the new entry automically.
Your patch looks better.
Andrew,
Anil's patch depends on the list.h updates currently in -mm
Quoted 1 line
Signed-off-by Anil S Keshavamurthy <[email protected]>
Quoted 20 lines
kernel/kprobes.c | 5 +---- 1 files changed, 1 insertion(+), 4 deletions(-)Index:
linux-2.6.15-rc5-mm1/kernel/kprobes.c
===================================================================kernel/kprobes.c +1
-4@@ -399,10 +399,7 @@ static inline void add_aggr_kprobe(strucINIT_LIST_HEAD (&ap->list);list_add_rcu (&p->list, &ap->list); -INIT_HLIST_NODE (&ap->hlist); -hlist_del_rcu (&p->hlist); -hlist_add_head_rcu (&ap->hlist, - &kprobe_table[hash_ptr (ap->addr,KPROBE_HASH_BITS )]); +hlist_replace_rcu (&p->hlist, &ap->hlist); }/*
Quoted 5 lines · Ananth N Mavinakayanahalli
Quoted 4 lines
Hi Ananth,
How do you like this patch? Here the old entry
will be replace with the new entry automically.
Quoted 7 lines
Your patch looks better.
Andrew,
Anil's patch depends on thelist.hupdates currently in -mmQuoted 1 line
Signed-off-by Anil S Keshavamurthy <[email protected]>
Am feeling particularly uncreative. Please resend with a changelog.
PATCH 1/1 kprobes: fix race in aggregate kprobe registration
In reply to Ananth N MavinakayanahalliWhen registering multiple kprobes at the same address, we leave a small window where the kprobe hlist will not contain a reference to the registered kprobe, leading to potentially, a system crash if the breakpoint is hit on another processor.
Patch below now automically relpace the old kprobe with the new kprobe from the hash list.
kernel/kprobes.c | 5 +---- 1 files changed, 1 insertion(+), 4 deletions(-)
kernel/kprobes.c +1 -4
@@ -399,10 +399,7 @@ static inline void add_aggr_kprobe(strucINIT_LIST_HEAD (&ap->list);list_add_rcu (&p->list, &ap->list); -INIT_HLIST_NODE (&ap->hlist); -hlist_del_rcu (&p->hlist); -hlist_add_head_rcu (&ap->hlist, - &kprobe_table[hash_ptr (ap->addr,KPROBE_HASH_BITS )]); +hlist_replace_rcu (&p->hlist, &ap->hlist); }/*