From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 B88574E77E4; Thu, 17 Sep 2026 15:49:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789660177; cv=none; b=mTkDqC4vA2NSmrkArzQAXSxbdY72/e9bz0RKfMEFGQUqYUK+ererFbceECaw5IsNXv0CU/hDLQ1P/TZhCsE8x9/qtbATgcVm963u4aozaNfDlJsFAa9cvxn8ZyG7q4aeqAblXIqLBBcN/Ht/2r0YV0ANfw2SIOCrrCrK9OEFQuI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789660177; c=relaxed/simple; bh=8Bxas/AlnzgWO4TozvSLFPHidm84QX7JBmySAjrES7E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ixrxFMlXC7gFHwfSXuvLUtc9LIUEt/8ypdIcOFfu0GzmPwNfw+ZH+kO9+ETXHK68QxCH0gN7N/r1usSf06IZSIGQBmki79B6s19zQV45Yg/8cnJQXo4KxwDu964ZYbn6TG+AS3i0uYXR48DwQR/rwZFotGK/FZuXD3Ll5uaOqHc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=IAT4Dmd8; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="IAT4Dmd8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 396CA1F000FF; Thu, 17 Sep 2026 15:49:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789660165; bh=Tm9a0jA4nz56/vkMN6ExzZq90J+LzZheGR4Ee1MLhpA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IAT4Dmd88m7toTQlDqsnIE3ZsGbopjw+Izt7nE+fNBtkWmaXGim7Xm1K0HEK58O2T /b/dns/hnpcYWkl7levQmefbxDGm+y98VyvlL6s7sIjz5WoiP1QfSlbFXco4S1UN+Q Bv4NgOOtbSzr6slTIuEM7XLnHhb6PwWPLZBp5RVQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko AI , Donggeun Yoo , Tom Zanussi , Steven Rostedt Subject: [PATCH 7.2 502/733] tracing: Take the reference before publishing the named histogram trigger Date: Thu, 17 Sep 2026 16:13:30 +0100 Message-ID: <20260917151404.607129107@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917151350.597953846@linuxfoundation.org> References: <20260917151350.597953846@linuxfoundation.org> User-Agent: quilt/0.69 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 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Donggeun Yoo commit 0fe23b8eaba0d3372c66b7b31204408da0715edc upstream. event_hist_trigger_named_init() puts the trigger on the global named_triggers list and only then takes the reference on the trigger it shares its histogram with: data->ref++; save_named_trigger(data->named_data->name, data); ret = event_hist_trigger_init(data->named_data); if (ret < 0) { kfree(data->cmd_ops); data->cmd_ops = &trigger_hist_cmd; } return ret; event_hist_trigger_init() fails when alloc_hist_pad() cannot allocate, and nothing takes the trigger back off the list on the way out. event_hist_trigger_parse() frees it, and the next lookup by name reads the freed object: BUG: KASAN: slab-use-after-free in find_named_trigger+0xac/0xc0 Read of size 8 at addr ffff888009346860 by task init/1 find_named_trigger+0xac/0xc0 hist_register_trigger+0xc1/0xa00 event_hist_trigger_parse+0x3146/0x6af0 event_trigger_write+0xce/0x160 Freed by task 67: kfree+0x154/0x420 trigger_kthread_fn+0xfd/0x160 Do the reference first and publish once it has succeeded, so that nothing which can fail runs after the trigger becomes findable. Cc: stable@vger.kernel.org Fixes: 7ab0fc61ce73 ("tracing: Move histogram trigger variables from stack to per CPU structure") Reported-by: Sashiko AI Closes: https://lore.kernel.org/linux-trace-kernel/20260907092944.3950E1F00A3D@smtp.kernel.org/ Link: https://patch.msgid.link/20260907124420.607097-2-donggeunyoo.kernel@gmail.com Signed-off-by: Donggeun Yoo Acked-by: Tom Zanussi Signed-off-by: Steven Rostedt Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace_events_hist.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -6360,17 +6360,18 @@ static int event_hist_trigger_named_init { int ret; - data->ref++; - - save_named_trigger(data->named_data->name, data); - ret = event_hist_trigger_init(data->named_data); if (ret < 0) { kfree(data->cmd_ops); data->cmd_ops = &trigger_hist_cmd; + return ret; } - return ret; + data->ref++; + + save_named_trigger(data->named_data->name, data); + + return 0; } static void event_hist_trigger_named_free(struct event_trigger_data *data)