From nobody Sat Feb 7 15:10:00 2026 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 715FCC4332F for ; Wed, 19 Oct 2022 13:20:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230106AbiJSNUy (ORCPT ); Wed, 19 Oct 2022 09:20:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231642AbiJSNUK (ORCPT ); Wed, 19 Oct 2022 09:20:10 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BB4D1DD893; Wed, 19 Oct 2022 06:05:42 -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 sin.source.kernel.org (Postfix) with ESMTPS id B7837CE2188; Wed, 19 Oct 2022 09:08:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB922C433D6; Wed, 19 Oct 2022 09:08:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170502; bh=if9Z3iTCK9QwPI7zMtkYtKKyLz8fKtzTU9GSQ7AW/0Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fHA5DtW3h9zXvCWEGoSih0gaYU7Xp19f9cVAMJQr8WBWVoK6T/V51jL5d5qHpmuVd OA3K71pQclLKKnBnIB6T01otq1Mpuo2p5FJ9yKLKY/4dH9yYsIqY0p9ebiqZOx6zUb H+DkFvOXOBdXRaFJ2gFxlhYTvWyt8sFW2fTNIvgc= 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 6.0 672/862] powercap: intel_rapl: fix UBSAN shift-out-of-bounds issue Date: Wed, 19 Oct 2022 10:32:39 +0200 Message-Id: <20221019083319.648230836@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@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 a2a2f4351463..33a3ca35cda0 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