From: Steven Rostedt <rostedt@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Andrew Morton <akpm@linux-foundation.org>,
sashiko-bot@kernel.org,
"Jose Fernandez (Anthropic)" <jose.fernandez@linux.dev>
Subject: [for-next][PATCH 7/9] ftrace: Do not leak a modules empty page group
Date: Mon, 19 Oct 2026 15:23:51 -0400 [thread overview]
Message-ID: <20261019192400.380770681@kernel.org> (raw)
In-Reply-To: 20261019192344.004592683@kernel.org
From: "Jose Fernandez (Anthropic)" <jose.fernandez@linux.dev>
When every mcount_loc entry of a module is skipped,
ftrace_process_locs() leaves the module's first page group linked
with no records. ftrace_release_mod() matches a module's groups by
records[0].ip, which is 0 here, so the group is never freed. While
it stays linked, ftrace_free_mem() reads pg->records[pg->index - 1]
with pg->index == 0 on every later module load, as lookup_rec() did
before commit ee92fa443358f ("ftrace: Fix invalid address access in
lookup_rec() when index is 0").
Unlink and free the new page groups when none of them got a record.
Link: https://patch.msgid.link/20260924-b4-arm64-callops-kcfi-v2-1-587865b6d991@linux.dev
Reported-by: sashiko-bot@kernel.org
Closes: https://lore.kernel.org/all/20260904013350.5141B1F000E9@smtp.kernel.org/
Assisted-by: LLM
Signed-off-by: Jose Fernandez (Anthropic) <jose.fernandez@linux.dev>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/ftrace.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 98535f5533db..c8f8dd1cb92f 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -7720,6 +7720,20 @@ static int ftrace_process_locs(struct module *mod,
rec->ip = addr;
}
+ /*
+ * ftrace_release_mod() finds a module's page groups by their first
+ * record. If every entry was skipped there is none, so unlink the
+ * new page groups and free them now.
+ */
+ if (mod && !start_pg->index) {
+ ftrace_pages->next = NULL;
+ mutex_unlock(&ftrace_lock);
+ /* Need to synchronize with ftrace_location_range() */
+ synchronize_rcu();
+ ftrace_free_pages(start_pg);
+ return 0;
+ }
+
if (pg->next) {
pg_unuse = pg->next;
pg->next = NULL;
--
2.53.0
next prev parent reply other threads:[~2026-10-19 19:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 19:23 [for-next][PATCH 0/9] tracing: Updates for 7.4 Steven Rostedt
2026-10-19 19:23 ` [for-next][PATCH 1/9] ftrace: Have stacktrace option work with func-args Steven Rostedt
2026-10-19 19:23 ` [for-next][PATCH 2/9] tracing: Avoid BTF lookup in atomic context Steven Rostedt
2026-10-19 19:23 ` [for-next][PATCH 3/9] ftrace: Build trace_btf.c when CONFIG_DEBUG_INFO_BTF is enabled Steven Rostedt
2026-10-19 19:23 ` [for-next][PATCH 4/9] fgraph: Enhance funcgraph-retval with BTF-based type-aware output Steven Rostedt
2026-10-19 19:23 ` [for-next][PATCH 5/9] tracing: Update funcgraph-retval documentation Steven Rostedt
2026-10-19 19:23 ` [for-next][PATCH 6/9] ftrace: Add max field to function profiler stats Steven Rostedt
2026-10-19 19:23 ` Steven Rostedt [this message]
2026-10-19 19:23 ` [for-next][PATCH 8/9] ftrace: Let ftrace_call_adjust() reject a patch site Steven Rostedt
2026-10-19 19:23 ` [for-next][PATCH 9/9] ftrace: Initialize modname and offset in print_rec() Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261019192400.380770681@kernel.org \
--to=rostedt@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=jose.fernandez@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=sashiko-bot@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.