From patchwork Mon Oct 24 11:31:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9142 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp457513wru; Mon, 24 Oct 2022 06:36:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4EIv6kA75Q26lSRwjbf9Ey3AC1wgEQHfwdn3YmiQexhqncr4tlDOpHPqf1x9lfnFwXGHmF X-Received: by 2002:a17:907:97c7:b0:79b:f7c7:35ec with SMTP id js7-20020a17090797c700b0079bf7c735ecmr13499954ejc.362.1666618568049; Mon, 24 Oct 2022 06:36:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618568; cv=none; d=google.com; s=arc-20160816; b=VVkVfUvK5XP+Jm8Y2z/V6LhRtHpCXar6ucY4lcVWATP1RADm+enf9KIXnEWxCOz61J Sr20Or5bB78g35OOHLNrEeya71CkmzFnY+8FLKRNIU2a88vr4NuqmSGXNBDkwie/H5qO E9cAUukN4nNDHkqtQq0+pbu8sxfPY02cVx+3/GE1XHR2gbGgLoRNPJCt7MqjVBel11Hh AwTK74WkqIhFE1PyYHgQuH6GryWsJDTO6JXJa7U8eJSpIUtOQFwyaIv8T1DqWIxI8Cy+ bz0QKr9fT6QfIsma1Nl7xKIcrUZEw6e72COjJMHYsmARtS9wfNrpl1vuKXF3RpOY8BTm /5TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=z88ZqQIWYE5GAUiXHsn6DX9DoS6IeTZcTk4Do9pPT0M=; b=Ie4BrXoCZM7pGhBXbSjHdv9u9xMIKt/VNFPqK4WY0hxB9FgLOPLsEq4kMOScl6/Z7Y cWDNloXxFh3O06xSFMVbTCQ2ygGbB0X/iRh+zEiJ9/f72pDLt4b+eQI8KcKQXKDNtaVq SXbwO9t6mZC7ai5iEUF1BRjUpiKzjqCPUpYh0x/Ne2/03XaX/DUVdZANbo8A1d4mlKQm rva/FEFPnASInYQlnJA5NjMN5K/UkMKolDJN7oD1k+LEuIWJM5fOgkckC3ZrCDUOEYR8 PInS6EPtk1F3oI+rJiJ8qO/0bpH+ppKeWuXgmRm1UdqF56D1eAQWr0ptya9FAzzN4iuA Pksg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=s9vHXgRq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b15-20020a056402350f00b0045bfaaab6d1si29293481edd.48.2022.10.24.06.35.27; Mon, 24 Oct 2022 06:36:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=s9vHXgRq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232711AbiJXN0E (ORCPT + 99 others); Mon, 24 Oct 2022 09:26:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229983AbiJXNXb (ORCPT ); Mon, 24 Oct 2022 09:23:31 -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 238095FF5D; Mon, 24 Oct 2022 05:30:14 -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 2EE45612FD; Mon, 24 Oct 2022 12:28:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E9DEC433D6; Mon, 24 Oct 2022 12:28:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614536; bh=GkeTiV1jLGPSKAFxenl8FDBEIWxxDohqsgMKG+3O+rU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s9vHXgRqDGbfWiqHs65y3LPodk1MWLaS7dB9vvJ3pyaa+2TgAi7W0WVsAmOHkuLM2 dTnEfI469rdllQM3D/67oQTldyKCCIUqS95Ul0RSQ2NYk3UJ13mZujyGBw1Er8PlBW V5SN1lnXgBBN7LtDFUyzhvb2uvMH0gOPyEH2g44Q= 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.10 299/390] powercap: intel_rapl: fix UBSAN shift-out-of-bounds issue Date: Mon, 24 Oct 2022 13:31:36 +0200 Message-Id: <20221024113035.746902883@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747576231312498616?= X-GMAIL-MSGID: =?utf-8?q?1747576231312498616?= 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 a13a07f475d2..285420c1eb7c 100644 --- a/drivers/powercap/intel_rapl_common.c +++ b/drivers/powercap/intel_rapl_common.c @@ -938,6 +938,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);