From nobody Fri Dec 19 18:43:04 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 297B8C3A59D for ; Sat, 22 Oct 2022 08:31:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233927AbiJVIbp (ORCPT ); Sat, 22 Oct 2022 04:31:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233939AbiJVI2u (ORCPT ); Sat, 22 Oct 2022 04:28:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC3542F668; Sat, 22 Oct 2022 01:01:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DF6AB60B93; Sat, 22 Oct 2022 07:59:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6803C433C1; Sat, 22 Oct 2022 07:59:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425586; bh=DWDmBHGO0wHz+DOiz6L+Y2WUHV5bbg+xFAMdEVqancE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MNsij98I5/VA3CYPFfgVON20X6GJ+xkyQUKXS0WhjxscgchAqpnFueuTpGA1QLbrH m5nqsZ41ttbEVHHbw7PChONn2zWNhlCS/6m6PC72O7fWSeOEL/wO7K8JK2glPCOPhy jn0rrOTGRORmiYOErW2elePSIK1TXUvqjcwAQLCM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chao Qin , Zhang Rui , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 5.19 549/717] powercap: intel_rapl: fix UBSAN shift-out-of-bounds issue Date: Sat, 22 Oct 2022 09:27:08 +0200 Message-Id: <20221022072522.652748958@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Chao Qin [ Upstream commit 2d93540014387d1c73b9ccc4d7895320df66d01b ] When value < time_unit, the parameter of ilog2() will be zero and the return value is -1. u64(-1) is too large for shift exponent and then will trigger shift-out-of-bounds: shift exponent 18446744073709551615 is too large for 32-bit type 'int' Call Trace: rapl_compute_time_window_core rapl_write_data_raw set_time_window store_constraint_time_window_us Signed-off-by: Chao Qin Acked-by: Zhang Rui Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/powercap/intel_rapl_common.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_= rapl_common.c index 684f177acb44..c053fac05cc2 100644 --- a/drivers/powercap/intel_rapl_common.c +++ b/drivers/powercap/intel_rapl_common.c @@ -994,6 +994,9 @@ static u64 rapl_compute_time_window_core(struct rapl_pa= ckage *rp, u64 value, y =3D value & 0x1f; value =3D (1 << y) * (4 + f) * rp->time_unit / 4; } else { + if (value < rp->time_unit) + return 0; + do_div(value, rp->time_unit); y =3D ilog2(value); f =3D div64_u64(4 * (value - (1 << y)), 1 << y); --=20 2.35.1