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=1796381381; b=zapw+tqefGSx+BZIp9Tl/sNWOjfpyWCCPiMjdOglkHRv+TkM0M3r6SSEGTmCcQTu5mwn 3R6CYYPEVXaZ3l/GrHMdxVV2S/x2EKcjSgaRg+CqZDJnY6z6wjzOVZJ/UVsDb8X6TKF7I d2X6yWLULtQrxs2wBbTyRowxYeXnq3vkYGZ8tyuyurFW+dzyjzLAm2KtzrYOZvl4CBOOJ el7Kfp7lGZASarqAbkJ50WasYpL0k5I//RL0sSo7fLHIyYGip15Ph9SPqm+JK2R7Ji4Mc vn98yTDRut/r6oklsI/NBxxORg1MJXf0deAdOhvVi1fHvt3yAaVeHpKmBq7M246W5ew== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381381; 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=Ejq0raOw0xZ8Z4LKWRBckl8QLCfavhFevrlsTyznIdE=; b=3Rp5Ts8SOaGYfiV2b1oteuuAlaOFNQRl+uGmoUcw8qMWqxaKJC1yKOQV7x1Zt5npfGGE 9Ewzb4s7xYvHGr0UbJmpdCG+LH+aiglnUinJWCmULdpCz3fut5Wmb3Thpyv2u3dMuq/Rq Uql32rerJ1qFGxbOgNCC/0Mtbbp+qnVI8HBQfHGk0UqAEMXPoW8sgybjIVxYPUx3OB+hI djHLRn/Cn+WJZN7y4sHtt50iRcqsvKVBpEKA5fKHamJGwXCKDVbYmLIyYXVsN2H1/IvPY d2Uda1GkPG27pgMWal4BstRAojp5jIbjWCq7DrqwfoYohcNQ2O/qif/b3LiHhAsXLOA== 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=YO6y2NKJ; 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 2DB56606A330; Fri, 4 Dec 2026 10:49:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=YO6y2NKJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CF441F000C2; Fri, 4 Dec 2026 10:49:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381381; bh=Ejq0raOw0xZ8Z4LKWRBckl8QLCfavhFevrlsTyznIdE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YO6y2NKJTut4khhzIJ1+BFF7J7Nxbwb/IA8rk7rCIYlJzOoKpjJW4a2Ndhvubk1Fw 9QW9qGwuNhKVkSEY33pwsFzKIzybpjnHl7PZpJQ1i1dbQmKkzpFueya8UzrLXoAKWM Fp/0155Ree/gBmIEAF++zZFKlpd7jldWH1UHiRbY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Baek Kyu, Kim" , Steven Rostedt Subject: [PATCH 7.3 679/742] tracing: Free tracer resources on instance creation failure Date: Fri, 4 Dec 2026 19:09:03 +0900 Message-ID: <20261204100653.095183210@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Baek Kyu, Kim commit a20691808762d48ae38191cf856878e4c901b553 upstream. Creating a tracefs instance can allocate private tracer nodes, copied flags and option arrays before trace_array_create_dir() returns. If a later allocation fails, trace_array_create_systems() frees the trace_array without releasing those private allocations. The failed instance is never registered, so normal removal cannot reclaim them. Free the tracer nodes and option arrays when trace_array_create_dir() fails, then continue through the existing trace_array cleanup. Share the option array cleanup with normal instance removal. Earlier failures still use out_free_tr because the tracer list is not yet initialized there. Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261029173127.387835-1-pocj8ur4in@gmail.com Fixes: 428add559b69 ("tracing: Have tracer option be instance specific") Signed-off-by: Baek Kyu, Kim Signed-off-by: Steven Rostedt Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -1456,6 +1456,13 @@ static void free_tracers(struct trace_ar } } +static void free_tracer_options(struct trace_array *tr) +{ + for (int i = 0; i < tr->nr_topts; i++) + kfree(tr->topts[i].topts); + kfree(tr->topts); +} + /** * register_tracer - register a tracer with the ftrace system. * @type: the plugin for the tracer @@ -8764,7 +8771,7 @@ trace_array_create_systems(const char *n if (trace_instance_dir) { ret = trace_array_create_dir(tr); if (ret) - goto out_free_tr; + goto out_free_tracers; } else __trace_early_add_events(tr); @@ -8774,6 +8781,9 @@ trace_array_create_systems(const char *n return tr; + out_free_tracers: + free_tracers(tr); + free_tracer_options(tr); out_free_tr: ftrace_free_ftrace_ops(tr); free_trace_buffers(tr); @@ -8927,10 +8937,7 @@ static int __remove_instance(struct trac if (tr->flags & TRACE_ARRAY_FL_VMALLOC) vfree((void *)tr->range_addr_start); - for (i = 0; i < tr->nr_topts; i++) { - kfree(tr->topts[i].topts); - } - kfree(tr->topts); + free_tracer_options(tr); free_cpumask_var(tr->pipe_cpumask); free_cpumask_var(tr->tracing_cpumask);