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 D2723551985; Wed, 30 Sep 2026 17:42:27 +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=1790790149; cv=none; b=BtYsm6zfn9bQp0wDA5I70IPBZMrV+l5Mz1btbeSCHUErFrfSsbZ/8Z+Yw+6BzVPhjdjMrvc1Z36X4ykHZZvMK0vCP7q0SYfccxPiEkcvjQLcNWBiNodT7Q9WQnCGa6sVepASxNU7bHWjDmAmcinmtyuNuWTmMst38aMniImAG0s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790790149; c=relaxed/simple; bh=9N7P+U4EOXnPK8LX8nfqFYuhXkYks3Pta5+lU3L+qew=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pxHJqFA+wtHITl1VvLPPTJ9QextY4hfgTF5tvG09emC/dzKx1JTlexlx8XDERvw0yz00TsPgQbG5lUxRNN5Y7LW3kftt3QSJCZwbtw+tNJeGuR3sTqlKjYCGpPU/CFQT1dOzeHScZBVrXCD00Y8/Pc3BEdGYAwmonapvGjjdMgs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Y9Q4fwKW; 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="Y9Q4fwKW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 205E51F00898; Wed, 30 Sep 2026 17:42:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790790147; bh=hN9BwsylpguRYjcdYYDs642kDrNgCwLn6hwp9BCFeaQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Y9Q4fwKWEyfOSweU9qLtYC8ydnX4ufQqto0kEvM53NDKkkjaUs60JSYyoCONiNmg/ LA16o3n2OJNqXE3hbxFmb3esiekLwYE6UDtQNRPvRPP27tEV+O6Rw+Yo7jvewx73Ao +RKeeaa5s/8D85uyrHZKrTg/ea70yWiuqh6FIkw0= 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 , Sasha Levin Subject: [PATCH 6.12 725/877] tracing: Take the reference before publishing the named histogram trigger Date: Wed, 30 Sep 2026 17:27:16 +0200 Message-ID: <20260930152430.331744256@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152414.738996857@linuxfoundation.org> References: <20260930152414.738996857@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 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Donggeun Yoo [ Upstream commit 0fe23b8eaba0d3372c66b7b31204408da0715edc ] 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: Sasha Levin 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 @@ -6327,17 +6327,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)