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=1796361790; b=lEMQMiUavy90yZT4kLeUCAl+LrNMptmpP2LNWbPt0hqfKPC3uTpmTM/ldF8eFchbXJLy CuumoyorwjU+xerBKk+wg7Mtp7Z7bXN+hhw8gEDxhWzsoXCZugKyzsN3A9i33V/IhfzEl O715CKR3vxD73YYu/JJfv5KYdWrjTVrF5YTawhmoLLrpycK+f3dvtAbhI8p+4KojzAngT uhcJMHSE8SShw9xkWCYnDsDnLGnnYcaOxc2pJiGzQizHjOzB3UtnI+XEoAMvhj2r05hqP y60IEck1h8EsAXhY9+1gu0RvJbHVc2+qu5ilIHynMJ5JxypRqfb/dyLIMsUGrrOT8fw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796361790; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=/miiZi4FE/qmEeviroc6x9WFY9xZSYp7rUN4lzoIiqM=; b=xJwn6wDKnI9CfSaYOREDlfH6rBxopNgx3WCRuAMmQuexI+uahf9rtWGHjtsH5gp/b+oX YBquV8Jh5glYhaWK0mNOaEnrAEHxHOCB+nsmd5dALtXEbeJprvbssoF7AI30VzZA0wQrm +nnA1PKjJATeJk2EKbp9ZplzzLPzfNcvTeFIbAd6OTVyHcFmu29WHq0psI7LFcZ9G/akT 5ifJLET+RpmG+fQU1AZKNhsgnlziwjSGJBTffH7xpkTXhd4ORUBe+O/3TqWx2ZwvasraP rSiT7T6n0MBPp46T8MC9YYuWGfClNY+szTBDIqQFY6Hh1Xta9ZGWXAH+GEGexOhL7UA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=i+TuEPHO; 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 BA5B4606A322 for ; Fri, 4 Dec 2026 05:23:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=i+TuEPHO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E9AE1F000CE; Fri, 4 Dec 2026 05:23:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796361790; bh=/miiZi4FE/qmEeviroc6x9WFY9xZSYp7rUN4lzoIiqM=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=i+TuEPHOVYKuzNfTsGC8kR1MjpkeXWI3k4ZogIqCVOEWU9RYDJTIohdjvrMZ4GSUR /3aha/pPgFi/UjocNBevHy7t+094+vfmRQcsZfI9VRikuuBKggay1zTebkDfi0jfPM QsJ3n48+Cyw/Ntdwr9MnuoBCMZAMCPCi729/WKpb490q5+cpN+daRxDFrn4yOjrSNn mbG7vrh51+xRooWvyeLeOWi/7oVcYEaQQlx87GiOaJCFaf/Bj8llx9uy0OmOElYdau qAxHK5fOfiOhWy/TiPKERgydXT8j8FnQCmsd4LmXgg/fq4qK3EZaoSSW+7iXXbnwHS Bd1UtLPx7QjnA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3] tracing/osnoise: validate and safely print sample runtime Reply-To: sashiko-reviews@lists.linux.dev To: "Kyuwon Cho" Cc: linux-trace-kernel@vger.kernel.org In-Reply-To: <179633331752.64245.15271121236897350387@skku.edu> References: <179633331752.64245.15271121236897350387@skku.edu> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 05:23:08 +0000 X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 tracing/osnoise: validate and safely print sample runtime This commit rejects zero osnoise sample runtimes, caps the osnoise period a= nd 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 =3D field->runtime - field->noise; > - ratio =3D net_runtime * 10000000; > - do_div(ratio, field->runtime); > - ratio_dec =3D do_div(ratio, 100000); > + ratio =3D 0; > + ratio_dec =3D 0; > + if (field->runtime) { > + net_runtime =3D field->runtime - field->noise; > + ratio =3D mul_u64_u64_div_u64(net_runtime, 10000000, > + field->runtime); > + ratio_dec =3D 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 n= ot trap on quotient overflow, so this is a regression. Although run_osnoise() checks for negative noise inside its loop, it captur= es start and last_sample in two separate time_get() calls without checking last_sample >=3D start: kernel/trace/trace_osnoise.c:run_osnoise() { ... start =3D time_get(); /* * "previous" loop. */ last_int_count =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/179633331752.64245.= 15271121236897350387@skku.edu?part=3D1