Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1179067rwi; Wed, 19 Oct 2022 07:34:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5BxBfP79f5vTabnqFtMhcsU1AKQEG22O7poHw6aIxJjFrlB/bI/JY/eyv/L5PG394Xf4if X-Received: by 2002:a05:6402:3890:b0:45c:2b5:b622 with SMTP id fd16-20020a056402389000b0045c02b5b622mr7905457edb.69.1666190090807; Wed, 19 Oct 2022 07:34:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666190090; cv=none; d=google.com; s=arc-20160816; b=UDhqhp456x3vNZCdRk0QzN+aBE564dm8/wDIPB8yem3Ntf0KoOCdb8f3CE45wGi7st 4tLXqSW5P+SJ4bF2zzaQNZljNPo0vFLoEyslQ4K8ftYzA5ewIVclY7qAM6xiMtRllyoZ oe3OHT2lf4sxbH7+1uyXvDKS/EOBM5Ge2x9u8Ql+0imFKn0lJotYZlDVRM+B9cFUJsRk L7UmiIvZC1d0Y13aUH+N5HcxIbvPBwODK3OVnp01DMWu+P00Esv3XthrUI8m++l9wDEc YhBkgTNR01TO6561Pz3jq/GiLi/86HGZb3iPoGZ4/TlwXie6rxpAQ1ABKes9VCUTX+ZM T1Yg== 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=JmAKnMZg75teQOjPbZwCL9oaXyCVokPiAv84dwVUck0=; b=Xfq2TsHeJX0+VkuxD1eqDgnHN2tzYDZ+Fv+ISLMUBWPo3hpOKDBNxhzW0SwszYqa3q QRE3+mplgU2rUUirzA3MrE2l8KPJ0/GbZiwD93IEiSqWeC5FJoGuZtiOXRa8rEzANCFM xujHBHeo3Xu+qvDTVSw08dfKRaBdktwtbru7+FIuVGGju4GqW1QwKOuS/sxNO0l4Xn5y e5aE8gDi12scdcC4E2pKu9oQ85hfRL8dX9Ghzok+KV9GSY9Yf7BKuhKDcZ5ozRBY+4+Y xK5jqf+3Akq9wC/5TlkRedmXOF1jx5/vMhoPaAiobF/jy3F/rrwwRGwobX0x+cUzfaHb VstA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fHA5DtW3; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m13-20020a056402510d00b0045d9ceae669si8666814edd.404.2022.10.19.07.34.24; Wed, 19 Oct 2022 07:34:50 -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=fHA5DtW3; 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 S232481AbiJSNUv (ORCPT + 99 others); Wed, 19 Oct 2022 09:20:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231642AbiJSNUK (ORCPT ); Wed, 19 Oct 2022 09:20:10 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BB4D1DD893; Wed, 19 Oct 2022 06:05:42 -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 sin.source.kernel.org (Postfix) with ESMTPS id B7837CE2188; Wed, 19 Oct 2022 09:08:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB922C433D6; Wed, 19 Oct 2022 09:08:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170502; bh=if9Z3iTCK9QwPI7zMtkYtKKyLz8fKtzTU9GSQ7AW/0Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fHA5DtW3h9zXvCWEGoSih0gaYU7Xp19f9cVAMJQr8WBWVoK6T/V51jL5d5qHpmuVd OA3K71pQclLKKnBnIB6T01otq1Mpuo2p5FJ9yKLKY/4dH9yYsIqY0p9ebiqZOx6zUb H+DkFvOXOBdXRaFJ2gFxlhYTvWyt8sFW2fTNIvgc= 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 6.0 672/862] powercap: intel_rapl: fix UBSAN shift-out-of-bounds issue Date: Wed, 19 Oct 2022 10:32:39 +0200 Message-Id: <20221019083319.648230836@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 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 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 a2a2f4351463..33a3ca35cda0 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