From patchwork Mon Oct 24 11:31:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8492 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp403836wru; Mon, 24 Oct 2022 04:53:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6JDaCyvbRRi4BdQnh/rfCbB8H6b71BPi+toStwfilQot6zx68lJkyLJoraef+tT5cKJlxo X-Received: by 2002:a17:902:9894:b0:186:a7d7:c56 with SMTP id s20-20020a170902989400b00186a7d70c56mr5239595plp.168.1666612413289; Mon, 24 Oct 2022 04:53:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666612413; cv=none; d=google.com; s=arc-20160816; b=DXTiBJD8LIXapddJugWOE2Jos0SfsgVI9TWp9kYqMqMZgqUkw51aE+muWx885sNbJ2 62pIj1oEoGWsfqaqLZHeuDgfdY+J9/0gGsCOCjCBZltq2/86k1Bj6GUWAj3FUwzv15fk QE38orCcu3VGEWR+JUArBhhBLnCXQB5oEHkkGWkz94971lTTXVXMFPENCagjKY2AKHZQ JBPSSraPi7lEJwjVQUHHtqvs+w95YIa0CN2iyx+Dob+GJ3AmwsFot22U/myoCAdxTKy+ fJd50p2ofFWRHSBcWFUUO59fbffLGosw2dlLRBJtIYhkzHbD7//WpUPSREWS1JA6JGcL kzwg== 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=QlIHshfNukdvE1XouPowFBjw9RNdJp0LcBkowOyCS1k=; b=aJL3JA3bU7lN46lL0E4EzsVJJW6xDPeYaikItUYFv6woCkm/qhmvaJ4cU/D5KH/0PJ 8aM0VsFfDUMWRhn0okDTxT7ZCUo2AMOeL0dpQiPAjvQXozWu3kcgRH2g2BaqhnKvY5tU 5I113rFPtOhWX8cc03zDhRcCDJYHNFrAG0xAqldWyv8s4d2CfuVoKAsTr2CxtVFvq3l0 8JFis0lZGPFWW+uPfU9xXx/7XR70Ni87lPwUq7UAy/1x+xVxmIBjeEUgmvQaIraLaHZy G1r/2cjvjGnEVW3xaYkY0unAvv4ROe1TI1gEJ5zG9KI3LjKeBeOPJBHiakirFCTpam+6 VeUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wi9JG5UI; 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 bk13-20020a056a02028d00b0043087ac1272si32288198pgb.586.2022.10.24.04.53.19; Mon, 24 Oct 2022 04:53:33 -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=wi9JG5UI; 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 S231259AbiJXLxH (ORCPT + 99 others); Mon, 24 Oct 2022 07:53:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232051AbiJXLwc (ORCPT ); Mon, 24 Oct 2022 07:52:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3C27209B9; Mon, 24 Oct 2022 04:44: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 ED28E61274; Mon, 24 Oct 2022 11:43:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AC02C433B5; Mon, 24 Oct 2022 11:43:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611823; bh=QXsB1UeFj8V1ql0mB2W4Auyo9lJtoymLc8ydxAXl2HQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wi9JG5UIfTVM6UlQ7eL1nnTdhknBslI7S49/jUBPR7+VFTY1W48RlPG8wphXbVIPy j3uxREB/lYeeLt6NOqJ7tdqC+E4chjBUJiZNi+wqaSx016UmsYnNv7Ro52Bufqrbts TVqwy3MBrZksGEWcnpCh7BENIOTPdJ9xy/R9yXRM= 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 4.9 125/159] powercap: intel_rapl: fix UBSAN shift-out-of-bounds issue Date: Mon, 24 Oct 2022 13:31:19 +0200 Message-Id: <20221024112954.072601249@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@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?1747569777927464694?= X-GMAIL-MSGID: =?utf-8?q?1747569777927464694?= 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 8809c1a20bed..5f31606e1982 100644 --- a/drivers/powercap/intel_rapl.c +++ b/drivers/powercap/intel_rapl.c @@ -1080,6 +1080,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);