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 4744151AEFC; Thu, 17 Sep 2026 17:44:02 +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=1789667043; cv=none; b=ZMKygLMm7BsdhXMIL9/EcbAlNJWl7S4E5lXsjfmmpqH1MxL7ohB2SbV3QihpxCqx0D+i16csw0g8nFRDi5jBQfHVCNpa5tiJnPwXN5rpNv3LnijSDU/5+g7mafIiEDguYymUhjYpKLY/SqWq7/NAA/sUlpA+ENfZ8J34Q5tM0HQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789667043; c=relaxed/simple; bh=/3SJlQezU0+vn8l+gwkhs0RsnGJMmmK1wSp3mf1VnYw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QwBT9wPTQ12THhOE3/PIBMjQU68RX84VrQpIM5Cm/RCW306hyFKWxUqpahtAIeQzVAfaeJhDwnZXJ6sgFL+wTs94NYU5IZgP74YtEa+PUTiAP5QqaXNISXcBdcRoq5EpbfNrz1U4Q3L2cVQ/jtT1AzM9QBnwmXZlQgAGUIaEqYo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=trW3plKL; 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="trW3plKL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6159B1F00893; Thu, 17 Sep 2026 17:44:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789667042; bh=HicGSVnqvnXULMqG/DYRlYtPbySy3Gw47bTJ6N7fZUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=trW3plKLudh1giq7scNZZVjyjDXzICzwCP0+Jm8/ayZ2aynYpA3eArXYFs8wP/FDv MybIt7Nicrw/4H4iSgNrAs/KYYWUcFTl4BBjLwB03+rVbBTcry1Y5OMjxW11bgfPdK R60NtYKL4IXMcbU27k8AIRxB6B/U9dAGeWmQtLnA= 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.18 1209/1250] tracing: Take the reference before publishing the named histogram trigger Date: Thu, 17 Sep 2026 16:16:44 +0100 Message-ID: <20260917151625.052435274@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917151551.901433442@linuxfoundation.org> References: <20260917151551.901433442@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.18-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 @@ -6355,17 +6355,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)