From: sashiko-bot@kernel.org
To: "Kyuwon Cho" <kyuwon.cho@skku.edu>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v3] tracing/osnoise: validate and safely print sample runtime
Date: Fri, 04 Dec 2026 05:23:08 +0000 [thread overview]
Message-ID: <sashiko-outbox-249139@kernel.org> (raw)
In-Reply-To: <179633331752.64245.15271121236897350387@skku.edu>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] tracing/osnoise: unchecked underflow in trace_osnoise_print()
--
commit 06b53da4388551e81287d6f227d53cd537058525
Author: Kyuwon Cho <kyuwon.cho@skku.edu>
tracing/osnoise: validate and safely print sample runtime
This commit rejects zero osnoise sample runtimes, caps the osnoise period and
sleep deadline to avoid ktime_t overflow, drops zero-duration samples in
run_osnoise(), and updates trace_osnoise_print() to guard against zero
runtime and use mul_u64_u64_div_u64().
> diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
> index 0850b3ad57075..adf03e8222a1b 100644
> --- a/kernel/trace/trace_output.c
> +++ b/kernel/trace/trace_output.c
[ ... ]
> @@ -1642,10 +1643,14 @@ trace_osnoise_print(struct trace_iterator *iter, int flags,
> /*
> * compute the available % of cpu time.
> */
> - net_runtime = field->runtime - field->noise;
> - ratio = net_runtime * 10000000;
> - do_div(ratio, field->runtime);
> - ratio_dec = do_div(ratio, 100000);
> + ratio = 0;
> + ratio_dec = 0;
> + if (field->runtime) {
> + net_runtime = field->runtime - field->noise;
> + ratio = mul_u64_u64_div_u64(net_runtime, 10000000,
> + field->runtime);
> + ratio_dec = do_div(ratio, 100000);
> + }
[Severity: Medium]
Can net_runtime underflow here and cause a divide-overflow exception in
mul_u64_u64_div_u64()?
On x86_64, mul_u64_u64_div_u64() uses raw mulq and divq instructions with no
exception table entry (arch/x86/include/asm/div64.h). When field->noise
exceeds field->runtime, net_runtime wraps to a large unsigned value and the
high 64 bits of net_runtime * 10000000 become 9999999.
For any field->runtime up to 9999999 us, including the default 1000000 us,
divq then traps with an unhandled divide-overflow exception and oopses the
kernel. Previously, the 64-bit multiplication wrapped and do_div() could not
trap on quotient overflow, so this is a regression.
Although run_osnoise() checks for negative noise inside its loop, it captures
start and last_sample in two separate time_get() calls without checking
last_sample >= start:
kernel/trace/trace_osnoise.c:run_osnoise() {
...
start = time_get();
/*
* "previous" loop.
*/
last_int_count = set_int_safe_time(osn_var, &last_sample);
...
}
If trace_clock_local() steps backward between those calls (for example, when
tsc_refine_calibration_work() updates cyc2ns), last_sample < start. The
first iteration then computes noise > total while passing the noise < 0
check, and can record a sample with field->noise > field->runtime.
Checking if (field->runtime > field->noise) instead of if (field->runtime)
would prevent both divide-by-zero and unsigned underflow.
--
Sashiko AI review · https://sashiko.dev/#/patchset/179633331752.64245.15271121236897350387@skku.edu?part=1
prev parent reply other threads:[~2026-12-04 5:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 5:04 [PATCH v3] tracing/osnoise: validate and safely print sample runtime Kyuwon Cho
2026-12-04 5:23 ` sashiko-bot [this message]
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=sashiko-outbox-249139@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kyuwon.cho@skku.edu \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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