From: Samuel Moelius <sam.moelius@trailofbits.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Samuel Moelius <sam.moelius@trailofbits.com>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
linux-kernel@vger.kernel.org (open list:FUNCTION HOOKS (FTRACE)),
linux-trace-kernel@vger.kernel.org (open list:FUNCTION HOOKS
(FTRACE))
Subject: [PATCH] samples/ftrace: reject zero ftrace-ops call count
Date: Tue, 9 Jun 2026 00:44:23 +0000 [thread overview]
Message-ID: <20260609004422.1239735.f6c06011af32.ftrace-ops-zero-function-calls-div0@trailofbits.com> (raw)
The ftrace-ops sample exposes nr_function_calls as a module parameter
and uses it as the divisor when printing the measured time per call.
Loading the module with nr_function_calls=0 skips the benchmark loop and
then divides the elapsed time by zero, crashing the kernel during sample
module initialization.
Reject a zero call count before registering any ftrace ops.
Assisted-by: Codex:gpt-5.5-cyber-preview
Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com>
---
samples/ftrace/ftrace-ops.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/samples/ftrace/ftrace-ops.c b/samples/ftrace/ftrace-ops.c
index 68d6685c80bd..d5adaa61484f 100644
--- a/samples/ftrace/ftrace-ops.c
+++ b/samples/ftrace/ftrace-ops.c
@@ -190,6 +190,11 @@ static int __init ftrace_ops_sample_init(void)
tracer_irrelevant = ops_func_count;
}
+ if (!nr_function_calls) {
+ pr_err("nr_function_calls must be non-zero\n");
+ return -EINVAL;
+ }
+
pr_info("registering:\n"
" relevant ops: %u\n"
" tracee: %ps\n"
--
2.43.0
next reply other threads:[~2026-06-09 0:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 0:44 Samuel Moelius [this message]
2026-06-09 1:03 ` Steven Rostedt
2026-06-09 11:26 ` Samuel Moelius
2026-06-11 0:03 ` Steven Rostedt
2026-06-29 15:23 ` Samuel Moelius
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=20260609004422.1239735.f6c06011af32.ftrace-ops-zero-function-calls-div0@trailofbits.com \
--to=sam.moelius@trailofbits.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®