From mboxrd@z Thu Jan 1 00:00:00 1970 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 DDE74C433F5 for ; Sun, 9 Oct 2022 20:52:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230285AbiJIUwy (ORCPT ); Sun, 9 Oct 2022 16:52:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230287AbiJIUwU (ORCPT ); Sun, 9 Oct 2022 16:52:20 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEE242D1C4; Sun, 9 Oct 2022 13:52:01 -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 ams.source.kernel.org (Postfix) with ESMTPS id CEC32B80DC2; Sun, 9 Oct 2022 20:51:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE2B2C433D6; Sun, 9 Oct 2022 20:51:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665348718; bh=NwwJETqj3AcSEg79DgmiIFZT+uXhZjs7LP8ts8YBLeo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=io8IVoWVXPX+c9Yob2vRrqnboE39YlsGIPNaw0ZC9OnpjLRsjRPSBlfkHme6tKnhj U/STK4XO/O3wdNqCs4mVdaD+G3vHpsOzjZpJSLZuHFEWK7D1webxe8nCjfnIufqBb2 aSELR88Og6BxfIuB/xZO2lbTevqpIJWXwBMUj30wtOW/j+GQY3vsOUMVgOOZgzn2Nv unArUuAFVQLNWXNkdMkagXHg/Xs7fm8XlUR5Ys0aAvLdUuOXQfeWCZkqNgQEHIo25T OTnVRmzBHX0t3zajXXvwawsFLerFxZglo26a7ocIVpON/YIhGuxg41uiRzzuZPS2YO QSTL7NUCfPFsg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Chao Qin , Zhang Rui , "Rafael J . Wysocki" , Sasha Levin , rafael@kernel.org, linux-pm@vger.kernel.org Subject: [PATCH AUTOSEL 6.0 12/18] powercap: intel_rapl: fix UBSAN shift-out-of-bounds issue Date: Sun, 9 Oct 2022 16:51:29 -0400 Message-Id: <20221009205136.1201774-12-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009205136.1201774-1-sashal@kernel.org> References: <20221009205136.1201774-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 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 21d624f9f5fb..bf91248630c3 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_package *rp, u64 value, y = value & 0x1f; value = (1 << y) * (4 + f) * rp->time_unit / 4; } else { + if (value < rp->time_unit) + return 0; + do_div(value, rp->time_unit); y = ilog2(value); f = div64_u64(4 * (value - (1 << y)), 1 << y); -- 2.35.1