uprobes: get RCU trace lock before list iteration
Subsystems (3)
PATCH 1/1 uprobes: get RCU trace lock before list iteration
Acquire RCU trace lock in filter_chain() to protect list_for_each_entry_rcu() iteration, protecting the list iteration in a RCU read section.
Prior to this fix, list_for_each_entry_srcu() was called without holding the required lock, triggering warnings when RCU_PROVING is enabled:
kernel/events/uprobes.c:937 RCU-list traversed without holding the required lock!!
--- kernel/events/uprobes.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/events/uprobes.c +2 -0
@@ -1103,11 +1103,13 @@ static bool filter_chain(struct uprobe *uprobe, struct mm_struct *mm)bool ret = false;down_read (&uprobe->consumer_rwsem); +rcu_read_lock_trace ();list_for_each_entry_rcu (uc, &uprobe->consumers, cons_node,rcu_read_lock_trace_held ()) { ret =consumer_filter (uc, mm);if (ret)break ; } +rcu_read_unlock_trace ();up_read (&uprobe->consumer_rwsem);return ret;
---
base-commit: 5b913f5d7d7fe0f567dea8605f21da6eaa1735fb
change-id: 20241107-rcu_probe-bef660d84990
Best regards,
Signature · 1 line
Breno Leitao <[email protected]>
Quoted 8 lines · Breno Leitao
Acquire RCU trace lock in
filter_chain()to protectlist_for_each_entry_rcu()iteration, protecting the list iteration in a RCU read section.Prior to this fix,
list_for_each_entry_srcu()was called without holding the required lock, triggering warnings whenRCU_PROVINGis enabled:
Quoted 7 lines
kernel/events/uprobes.c:937RCU-list traversed without holding the required lock!!Signed-off-by Breno Leitao <[email protected]>Fixes cc01bd044e6a ("uprobes: travers uprobe's consumer list locklessly under SRCU protection")--- kernel/events/uprobes.c | 2 ++ 1 file changed, 2 insertions(+)
LGTM, thanks
Quoted 28 lines
kernel/events/uprobes.c +2
-1@@ -1103,11 +1103,13 @@ static bool filter_chain(struct uprobe *uprobe, struct mm_struct *mm)bool ret = false;down_read (&uprobe->consumer_rwsem); +rcu_read_lock_trace ();list_for_each_entry_rcu (uc, &uprobe->consumers, cons_node,rcu_read_lock_trace_held ()) { ret =consumer_filter (uc, mm);if (ret)break ; } +rcu_read_unlock_trace ();up_read (&uprobe->consumer_rwsem);return ret; ---base-commit:
5b913f5d7d7fe0f567dea8605f21da6eaa1735fb
change-id: 20241107-rcu_probe-bef660d84990Best regards,
--
Breno Leitao <[email protected]>
Peter Zijlstra
maintainerQuoted 20 lines · Breno Leitao
Acquire RCU trace lock in
filter_chain()to protectlist_for_each_entry_rcu()iteration, protecting the list iteration in a RCU read section.Prior to this fix,
list_for_each_entry_srcu()was called without holding the required lock, triggering warnings whenRCU_PROVINGis enabled:
kernel/events/uprobes.c:937RCU-list traversed without holding the required lock!!Signed-off-by Breno Leitao <[email protected]>Fixes cc01bd044e6a ("uprobes: travers uprobe's consumer list locklessly under SRCU protection")--- kernel/events/uprobes.c | 2 ++ 1 file changed, 2 insertions(+)kernel/events/uprobes.c +0
-0
kernel/events/uprobes.c static bool filter_chain(struct uprobe *uprobe, struct mm_struct *mm) · line 1107
Quoted 5 lines
kernel/events/uprobes.c +1
-0@@ -1103,11 +1103,13 @@ static bool filter_chain(struct uprobe *uprobe, struct mm_struct *mm)bool ret = false;down_read (&uprobe->consumer_rwsem); +rcu_read_lock_trace ();list_for_each_entry_rcu (uc, &uprobe->consumers, cons_node,rcu_read_lock_trace_held ()) {
Maybe I'm confused, but isn't uprobe->consumer list protected by uprobe->consumer_rwsem, which we hold for reading?
That is, AFAICT this is a false positive and we should be doing this instead, no?
kernel/events/uprobes.c +1 -1
@@ -1104,7 +1104,7 @@ static bool filter_chain(struct uprobe *uprobe, struct mm_struct *mm)bool ret = false;down_read (&uprobe->consumer_rwsem); -list_for_each_entry_rcu (uc, &uprobe->consumers, cons_node,rcu_read_lock_trace_held ()) { +list_for_each_entry (uc, &uprobe->consumers, cons_node) { ret =consumer_filter (uc, mm);if (ret)break ;
Andrii Nakryiko
Acked-byQuoted 31 lines · Peter Zijlstra
Quoted 20 lines · Breno Leitao
Acquire RCU trace lock in
filter_chain()to protectlist_for_each_entry_rcu()iteration, protecting the list iteration in a RCU read section.Prior to this fix,
list_for_each_entry_srcu()was called without holding the required lock, triggering warnings whenRCU_PROVINGis enabled:
kernel/events/uprobes.c:937RCU-list traversed without holding the required lock!!Signed-off-by Breno Leitao <[email protected]>Fixes cc01bd044e6a ("uprobes: travers uprobe's consumer list locklessly under SRCU protection")--- kernel/events/uprobes.c | 2 ++ 1 file changed, 2 insertions(+)kernel/events/uprobes.c +0
-0kernel/events/uprobes.c static bool filter_chain(struct uprobe *uprobe, struct mm_struct *mm) · line 1107
Quoted 5 lines
kernel/events/uprobes.c +1
-0@@ -1103,11 +1103,13 @@ static bool filter_chain(struct uprobe *uprobe, struct mm_struct *mm)bool ret = false;down_read (&uprobe->consumer_rwsem); +rcu_read_lock_trace ();list_for_each_entry_rcu (uc, &uprobe->consumers, cons_node,rcu_read_lock_trace_held ()) {Maybe I'm confused, but isn't
uprobe->consumerlist protected byuprobe->consumer_rwsem, which we hold for reading?
Quoted 2 lines
That is, AFAICT this is a false positive and we should be doing this instead, no?
Yep, you are absolutely right. RCU-protected traversal is important only for handler_chain() and handle_uretprobe_chain(). Here it's all under lock, so no need for RCU protection.
kernel/events/uprobes.c static bool filter_chain(struct uprobe *uprobe, struct mm_struct *mm) · line 1107
Quoted 12 lines
kernel/events/uprobes.c +1
-1@@ -1104,7 +1104,7 @@ static bool filter_chain(struct uprobe *uprobe, struct mm_struct *mm)bool ret = false;down_read (&uprobe->consumer_rwsem); -list_for_each_entry_rcu (uc, &uprobe->consumers, cons_node,rcu_read_lock_trace_held ()) { +list_for_each_entry (uc, &uprobe->consumers, cons_node) {
Quoted 3 lines
kernel/events/uprobes.c +0
-0ret =consumer_filter (uc, mm);if (ret)break ;
Quoted 32 lines · Andrii Nakryiko
Quoted 31 lines · Peter Zijlstra
Quoted 20 lines · Breno Leitao
Acquire RCU trace lock in
filter_chain()to protectlist_for_each_entry_rcu()iteration, protecting the list iteration in a RCU read section.Prior to this fix,
list_for_each_entry_srcu()was called without holding the required lock, triggering warnings whenRCU_PROVINGis enabled:
kernel/events/uprobes.c:937RCU-list traversed without holding the required lock!!Signed-off-by Breno Leitao <[email protected]>Fixes cc01bd044e6a ("uprobes: travers uprobe's consumer list locklessly under SRCU protection")--- kernel/events/uprobes.c | 2 ++ 1 file changed, 2 insertions(+)kernel/events/uprobes.c +0
-0kernel/events/uprobes.c static bool filter_chain(struct uprobe *uprobe, struct mm_struct *mm) · line 1107
Quoted 5 lines
kernel/events/uprobes.c +1
-0@@ -1103,11 +1103,13 @@ static bool filter_chain(struct uprobe *uprobe, struct mm_struct *mm)bool ret = false;down_read (&uprobe->consumer_rwsem); +rcu_read_lock_trace ();list_for_each_entry_rcu (uc, &uprobe->consumers, cons_node,rcu_read_lock_trace_held ()) {Maybe I'm confused, but isn't
uprobe->consumerlist protected byuprobe->consumer_rwsem, which we hold for reading?
Quoted 6 lines
Quoted 2 lines
That is, AFAICT this is a false positive and we should be doing this instead, no?
Yep, you are absolutely right. RCU-protected traversal is important only for
handler_chain()andhandle_uretprobe_chain(). Here it's all under lock, so no need for RCU protection.
Thanks. I will update