Re: [PATCH] uprobes: get RCU trace lock before list iteration

From: Andrii Nakryiko
Date: Thu Nov 07 2024 - 13:16:08 EST


On Thu, Nov 7, 2024 at 9:16 AM Breno Leitao <leitao@xxxxxxxxxx> wrote:
>
> 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!!
>
> Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
> Fixes: cc01bd044e6a ("uprobes: travers uprobe's consumer list locklessly under SRCU protection")
> ---
> kernel/events/uprobes.c | 2 ++
> 1 file changed, 2 insertions(+)

LGTM, thanks

Reviewed-by: Andrii Nakryiko <andrii@xxxxxxxxxx>

>
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index fa04b14a7d72353adc440742016b813da6c812d2..afdaa45a43ac3948f7983175eda808c989e8738a 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -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,
> --
> Breno Leitao <leitao@xxxxxxxxxx>
>