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 7935A3054DD; Tue, 2 Sep 2025 13:44: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=1756820670; cv=none; b=qCRSlX26J6JA5kIhuf3UJthkQcCHSy5jZYqg+PABo7857y95K6K2tntKMpnWfzPDl+V3a0f9srfhzAzNT2HuZlU2gsa5BpH9+GL66jIGSfWAlvEJLZfH4AjhR2GGgDPVY4CZEsKc6RIY+xFlsowqQkaNqXt0doJp4+ItTnF58C4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756820670; c=relaxed/simple; bh=7he5TZ34zSoeQqcO7keu/MoQxmT60D33CqLRObblGCg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JHFHV5m4Ch0FjsPt294HG94BcLikax5x4ipxtXxj9IWYheZH1WGtcypUFrx8v9TDdtkGjzGHw0zV4SRflckBhWVM1vNVqtozxNaYZdPprjJ9/IBp6PuGHArEONPlRYZ6ZPSyMZoGVDQAMiU8XLqgtKmibdF1eGzQqmySy1RAdoM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=HrqcqbdC; 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="HrqcqbdC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFCD6C4CEED; Tue, 2 Sep 2025 13:44:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1756820670; bh=7he5TZ34zSoeQqcO7keu/MoQxmT60D33CqLRObblGCg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HrqcqbdCsHbxwCNe+OYOR8lR7yHhDonSU3SHRBuvw8mxwBPKULAso9IM5d4DZ4UU5 iMSqLtEF9RCyHEUu5Qdh5eaRvKGpRh26SkwE5MS9qeY3rr2hIGOgj4idwNtC5/rvFl RwO6Faf01kegWMD4mTgShNGShaBfN+QxD+q+8Zrw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Ingo Molnar , Tengda Wu , "Steven Rostedt (Google)" , Sasha Levin Subject: [PATCH 5.10 02/34] ftrace: Fix potential warning in trace_printk_seq during ftrace_dump Date: Tue, 2 Sep 2025 15:21:28 +0200 Message-ID: <20250902131926.709996468@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250902131926.607219059@linuxfoundation.org> References: <20250902131926.607219059@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tengda Wu [ Upstream commit 4013aef2ced9b756a410f50d12df9ebe6a883e4a ] When calling ftrace_dump_one() concurrently with reading trace_pipe, a WARN_ON_ONCE() in trace_printk_seq() can be triggered due to a race condition. The issue occurs because: CPU0 (ftrace_dump) CPU1 (reader) echo z > /proc/sysrq-trigger !trace_empty(&iter) trace_iterator_reset(&iter) <- len = size = 0 cat /sys/kernel/tracing/trace_pipe trace_find_next_entry_inc(&iter) __find_next_entry ring_buffer_empty_cpu <- all empty return NULL trace_printk_seq(&iter.seq) WARN_ON_ONCE(s->seq.len >= s->seq.size) In the context between trace_empty() and trace_find_next_entry_inc() during ftrace_dump, the ring buffer data was consumed by other readers. This caused trace_find_next_entry_inc to return NULL, failing to populate `iter.seq`. At this point, due to the prior trace_iterator_reset, both `iter.seq.len` and `iter.seq.size` were set to 0. Since they are equal, the WARN_ON_ONCE condition is triggered. Move the trace_printk_seq() into the if block that checks to make sure the return value of trace_find_next_entry_inc() is non-NULL in ftrace_dump_one(), ensuring the 'iter.seq' is properly populated before subsequent operations. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Ingo Molnar Link: https://lore.kernel.org/20250822033343.3000289-1-wutengda@huaweicloud.com Fixes: d769041f8653 ("ring_buffer: implement new locking") Signed-off-by: Tengda Wu Signed-off-by: Steven Rostedt (Google) Signed-off-by: Sasha Levin --- kernel/trace/trace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 0c7aa47fb4d3b..d08320c47a150 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -9617,10 +9617,10 @@ void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) ret = print_trace_line(&iter); if (ret != TRACE_TYPE_NO_CONSUME) trace_consume(&iter); + + trace_printk_seq(&iter.seq); } touch_nmi_watchdog(); - - trace_printk_seq(&iter.seq); } if (!cnt) -- 2.50.1