From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793213453; b=dzg63HpectowPLhTrxaHdCwwpmjF92Ao/1HieZ6yKwxs103D+P3zsxgINTu5iGeOPDYv 69A98TSzi6985wSAulWwFobMN1TMfLJHlSbr712feQP2p4SmZH8yE05la8CCHGhSdELwc 7vs63qnlHeuqVZ/WWuOAlLfeQpNF1GLosHA3lcshWjVLNB8AufluwmSfEx7xYtoW//G1p QoHyQpkkJEMWSDP3aSQlZp8o//hqHRZO3bdC9y0hJvNEM9fakOciTsfzy4zjAH1BCMRkV +LIZ4bHuZhQRdEwp65IYn7J7jHyFevaJgUeBpZRxYvA6K6KKpIYEVutlgPUh7/f3lSw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793213453; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=6YmWcBpKBpyBXHeUIyGU2iQpafQ+I9ONd/gWwV6p1tk=; b=xxIrKwEGBejxoR8s6hzz0nEAoU10uI5tW+M8mjvKRpFMUwqb3e7XgVISzyu/vz/zRkTe ZgGXheQtYozkLf6RTTcLX7MoGzqIEj1i9QvcjwAihpXduMFkj16NeBpoWSJub6TjBYozS Jz64HIM251fUaAADUIgYk9oTkwzRvtGxF8px8+TFfU4wgXAZaToWF6HzY3iBj4qISMfLE z5Dgft8lmOYZGZr2srswVkuMZyYhySCVo0JrFkYXvGFIx2LMc0/lr33MaiqLFre9e9eSt vSSK74FeMmVPkLn7K8pRykX09Bq4xRlc4PHl9L0IHOJ7Qu9dE2L+Ev77d8Xyauh8Pww== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=FO0JyMkZ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85E6C606A31D; Wed, 28 Oct 2026 18:50:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=FO0JyMkZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6A441F01825; Wed, 28 Oct 2026 18:50:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793213453; bh=6YmWcBpKBpyBXHeUIyGU2iQpafQ+I9ONd/gWwV6p1tk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FO0JyMkZaUPj8DP5ex8LArGa+38OU0+0GfJyATpnfEs++GSDcj3mwJ4EnMDZhD93d IyWuxMdWLSdZP5jaS27+BIpSxkS8PaQr8yYS0gBzHs9bxln//YiOgZsdatwsdVo/ds QOCD63lGVAzgDbQU7H3dsDj5SWuKKI67sL4zqzcY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Donggeun Yoo , Steven Rostedt , Lee Jones , Sasha Levin Subject: [PATCH 6.1 0511/1887] tracing: Set the trace clock before registering the histogram trigger Date: Wed, 28 Oct 2026 17:43:27 +0100 Message-ID: <20261028170510.940784770@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028170459.200466217@linuxfoundation.org> References: <20261028170459.200466217@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Donggeun Yoo [ Upstream commit 6ede78d0563a2a3ae3e46f9c07cedb5d79645429 ] hist_register_trigger() puts the trigger on the global named_triggers list in cmd_ops->init(), and only then sets the trace clock: if (data->cmd_ops->init) { ret = data->cmd_ops->init(data); if (ret < 0) goto out; } if (hist_data->enable_timestamps) { ret = tracing_set_clock(file->tr, hist_data->attrs->clock); if (ret) { hist_err(tr, HIST_ERR_SET_CLOCK_FAIL, errpos(clock)); goto out; } The clock string is not checked anywhere before that call, so a named trigger using common_timestamp with an unknown clock fails after it has already become findable. event_hist_trigger_parse() then frees it without taking it off the list, and the next lookup by name reads the freed object: ~# cd /sys/kernel/tracing/events/sched/sched_switch ~# echo 'hist:name=foo:keys=common_pid:ts=common_timestamp:clock=bogus' > trigger bash: echo: write error: Invalid argument ~# echo 'hist:name=foo:keys=common_pid' > trigger BUG: KASAN: slab-use-after-free in find_named_trigger+0xac/0xc0 Read of size 8 at addr ffff88800915d760 by task init/1 find_named_trigger+0xac/0xc0 hist_register_trigger+0xc1/0x900 event_hist_trigger_parse+0x3146/0x6af0 event_trigger_write+0xce/0x160 Freed by task 63: kfree+0x154/0x420 trigger_kthread_fn+0xfd/0x160 Set the clock before the trigger is registered, so that nothing which can fail runs after it is published, the way commit 6f86bdeab633 ("tracing: Fix bad hist from corrupting named_triggers list") moved the registration below the rest of the setup. tracing_set_filter_buffering() is reference counted, so the init failure path has to drop the reference that the clock block now takes first. Cc: stable@vger.kernel.org Fixes: a4072fe85ba3 ("tracing: Add a clock attribute for hist triggers") Link: https://patch.msgid.link/20260907091415.554535-1-donggeunyoo.kernel@gmail.com Signed-off-by: Donggeun Yoo Signed-off-by: Steven Rostedt [Lee: Call data->ops->init(data) as b052d70f7c9c ("tracing: Merge struct event_trigger_ops into struct event_command") is not present] Signed-off-by: Lee Jones Signed-off-by: Sasha Levin --- kernel/trace/trace_events_hist.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index 8e5efdfa0fc7a..7753a024829b8 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -6244,12 +6244,6 @@ static int hist_register_trigger(char *glob, data->ops = &event_hist_trigger_named_ops; } - if (data->ops->init) { - ret = data->ops->init(data); - if (ret < 0) - goto out; - } - if (hist_data->enable_timestamps) { char *clock = hist_data->attrs->clock; @@ -6262,6 +6256,15 @@ static int hist_register_trigger(char *glob, tracing_set_filter_buffering(file->tr, true); } + if (data->ops->init) { + ret = data->ops->init(data); + if (ret < 0) { + if (hist_data->enable_timestamps) + tracing_set_filter_buffering(file->tr, false); + goto out; + } + } + if (named_data) { remove_hist_vars(hist_data); destroy_hist_data(hist_data); -- 2.53.0