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 86180C4332F for ; Sun, 9 Oct 2022 21:13:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230140AbiJIVNR (ORCPT ); Sun, 9 Oct 2022 17:13:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231477AbiJIVMz (ORCPT ); Sun, 9 Oct 2022 17:12:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C5043CBD4; Sun, 9 Oct 2022 14:07:37 -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 335D860CEF; Sun, 9 Oct 2022 20:54:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9FB0C433D7; Sun, 9 Oct 2022 20:54:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665348889; bh=D10J9yBbVDhCPyPeEabyHA9i/KE6B7sbMw0ny/UqgeY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jSndVzl5kTGl8vTyLoCjnxk/NT1szxB6pgluItBMYZIJTkDS6/odOilEAH1DOY0VY RJcqBW5lzWUfcb8TuZlvQE7+O79k0KGWXLdgm6dfdULtE0eIbX3vOvEq3kNAJ9WJip bB5Fi8pSIki0hqxG6FmU1f18JHn3gDP0qtaqfcwRLGh9HrCrtApqnlP3rPAoPRTTqe fSPrLaYZU54TPptRUAURj9p/5B3A9RldIDolZdwYWnuHPm8yW3N+oEbp5l68U2hpQc aUkW/FU3ciBHK9+yUC+Jsiwj3S6XD+EHY5Js5/kio64jux0fO9FVeerkHW8s3AS9Mr nyQoO2x+HmbEg== 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 4.19 3/6] powercap: intel_rapl: fix UBSAN shift-out-of-bounds issue Date: Sun, 9 Oct 2022 16:54:39 -0400 Message-Id: <20221009205443.1203725-3-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009205443.1203725-1-sashal@kernel.org> References: <20221009205443.1203725-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: linux-kernel@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.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c index 8cbfcce57a06..ae6721333c0f 100644 --- a/drivers/powercap/intel_rapl.c +++ b/drivers/powercap/intel_rapl.c @@ -1068,6 +1068,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