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 206F5C4332F for ; Sun, 9 Oct 2022 20:55:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231146AbiJIUzG (ORCPT ); Sun, 9 Oct 2022 16:55:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230463AbiJIUxy (ORCPT ); Sun, 9 Oct 2022 16:53:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA63D30F75; Sun, 9 Oct 2022 13:52:46 -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 DB08B60C79; Sun, 9 Oct 2022 20:52:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70432C433C1; Sun, 9 Oct 2022 20:52:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665348765; bh=Xxzfdx44RcOTS7g3/gAkGQlDLPes5mmdfMh3VInZF9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j7/xOLdB7KaKG2uAomZMjWUT6NnmcwNNaCjXrAfULFHbr7ODpY7PHHL1qHeQMAs9R p/wKM/5iOW4ImtiUqz6wXP0FLM/QiwT6pHl/2vVlr5rfhV1haV6zOawzYWb9UV4nDD Fm1sAP3iPnKbMu6ign1lq5NZUhWIm7Zyndpwb1uUdikkQ0Bjhyp4MCb5pFdy6fMlJq nV2F9vKD1/FgqSKvCvp4+XtV/XrwrNsqJZnK+ETxh4JHrtkedBWNOx2+u9J37EBb7Q IKlhTaSVu9Fkv84plssiMkZco/N1+93jA4R+5IjhzyUGuUDV3XG4hfKgrAf4tINwHO nt0kul0heHl/w== 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 5.19 10/16] powercap: intel_rapl: fix UBSAN shift-out-of-bounds issue Date: Sun, 9 Oct 2022 16:52:19 -0400 Message-Id: <20221009205226.1202133-10-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009205226.1202133-1-sashal@kernel.org> References: <20221009205226.1202133-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_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 a9c99d9e8b42..4aab9d6cc7e1 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