From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C44CB78F3A; Wed, 5 Mar 2025 18:01:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741197690; cv=none; b=psBOTjHxUi2OZxRpr8zh52W9BcqrMqd6K7sW6Xjnpt476Q51IQPoCbozQnaJUbl1nU2v0VS0F4JMtFQhachquWL4vXaXfuDDgPs3ovfghIXabBJ7QnobYWuOhbVhT+cQs1LMu1EgrwoE6gsC9hmt1t0xw15L121ckY54QpHR/8U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741197690; c=relaxed/simple; bh=EfJQEFCtps7qs1oegcLrqBYgPc2o7z65scb6EVFQfzs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Yr+6yC3Q7w0cwVnb+Y+fg/WZ4UcDFRaiKYWD4ANzFcOn2xaBFgJZ6dmTvOXvsdIJFDuJgt6LZMVcPqXNl9Bu2vGvfinnWOqtGK6dT/J4XEBeUSDdv+s4lKfFhzAOYfFwcq41SJRdt/qvfCU7HXH1VX8lRKDp/MGCuEV0nw5mWxM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jredjNEG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="jredjNEG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D855EC4CEE2; Wed, 5 Mar 2025 18:01:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1741197690; bh=EfJQEFCtps7qs1oegcLrqBYgPc2o7z65scb6EVFQfzs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jredjNEG9uVNGjuUCASoTNPRskzwzqfA+vJWU9GLhILb6He3VfAdxbU7WlbUlvDuB QfFJkbe++b3NkHvaNhQ1Ccxj5fQXDEkkem2pVdsNAZHV+ATFg/P4jWbNTMDalnTA9J H3MwB7/20Bltm1NU77DIPXPPvfX2Gvak+tsrZ5kI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Breno Leitao , Ingo Molnar , "Peter Zijlstra (Intel)" Subject: [PATCH 6.6 065/142] perf/core: Add RCU read lock protection to perf_iterate_ctx() Date: Wed, 5 Mar 2025 18:48:04 +0100 Message-ID: <20250305174502.951480763@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250305174500.327985489@linuxfoundation.org> References: <20250305174500.327985489@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Breno Leitao commit 0fe8813baf4b2e865d3b2c735ce1a15b86002c74 upstream. The perf_iterate_ctx() function performs RCU list traversal but currently lacks RCU read lock protection. This causes lockdep warnings when running perf probe with unshare(1) under CONFIG_PROVE_RCU_LIST=y: WARNING: suspicious RCU usage kernel/events/core.c:8168 RCU-list traversed in non-reader section!! Call Trace: lockdep_rcu_suspicious ? perf_event_addr_filters_apply perf_iterate_ctx perf_event_exec begin_new_exec ? load_elf_phdrs load_elf_binary ? lock_acquire ? find_held_lock ? bprm_execve bprm_execve do_execveat_common.isra.0 __x64_sys_execve do_syscall_64 entry_SYSCALL_64_after_hwframe This protection was previously present but was removed in commit bd2756811766 ("perf: Rewrite core context handling"). Add back the necessary rcu_read_lock()/rcu_read_unlock() pair around perf_iterate_ctx() call in perf_event_exec(). [ mingo: Use scoped_guard() as suggested by Peter ] Fixes: bd2756811766 ("perf: Rewrite core context handling") Signed-off-by: Breno Leitao Signed-off-by: Ingo Molnar Acked-by: Peter Zijlstra (Intel) Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20250117-fix_perf_rcu-v1-1-13cb9210fc6a@debian.org Signed-off-by: Greg Kroah-Hartman --- kernel/events/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -8113,7 +8113,8 @@ void perf_event_exec(void) perf_event_enable_on_exec(ctx); perf_event_remove_on_exec(ctx); - perf_iterate_ctx(ctx, perf_event_addr_filters_exec, NULL, true); + scoped_guard(rcu) + perf_iterate_ctx(ctx, perf_event_addr_filters_exec, NULL, true); perf_unpin_context(ctx); put_ctx(ctx);