From patchwork Mon Oct 24 11:31:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9250 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp461290wru; Mon, 24 Oct 2022 06:43:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6m+okJLc5DxwvJ1WWTMpeX1Bx/cFL+BVey2ryfWFih8m76i77C69q+wIz1cbitp9+uLdU/ X-Received: by 2002:a17:907:97c3:b0:79b:3f8d:a354 with SMTP id js3-20020a17090797c300b0079b3f8da354mr14580141ejc.461.1666619014213; Mon, 24 Oct 2022 06:43:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666619014; cv=none; d=google.com; s=arc-20160816; b=CUX8liwj37eONxRaSAoXLkNYRZmtiPDjucT2Oq7mJokoPKl+LUbUuY3JKC2yQY4074 ywDRS/7y6Xjm5DUPtAPLOwBCCYa7SW3dgEuUT9DmKfxU4t/stGgomUD8qxmwNgpyRJoN UFRf9h1g4qg5tQ3WQsdgyvz8glplAW7uxSFdpquJwnaPGgMYv9kMh/Es9EN7tpUVrhMj VCLqNk8F+YvEJ6oMzB2yp2bxL+Jw+zU5Vn2zmGJpvbBZJzfZVZU80P9BsPwVYClfnaVG HzBK8ryE74QMjP+bszMqi4snwRK2khLAgwfvH5PmGp8ymIdDNgmUvzlyfwXDp6GWa7SG 6Clw== 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=/yDTfWCy8USd/4nXl5/TaL6ci1dkDOaS8nuKmakgsDI=; b=pavWBbpB+rqITNPpLa0y5Y5WPhskJBXIpiaPdRJAuVJfpqDPDWQ/RxT+O2G4nU9Von 2YqXVTP69p7YSNK+VrCwkli4cfd9/BeCqcHWwmp37S3lpF38JPJfrQYt1vWTUvIqzDgL PBWpTzT8Jbz0Z60Eqoiq4Lw07qIFyVopjoj1iZNBHBvVWDfX2F+nEX7jim+urpyqaQ4g /8HB+7/gfMtaWBmS4M+39laLmQJq1RUHFFagvaSIansX6sp+DJJh4yzdr6fHagoX3pOR +jlVwbaSC+hscMYYtnWtn9PW5kbmE74226zhM4TdIjXzxt9BmEtkOJWIZprVXyyRUEO3 BwLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GoOQgGqp; 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 ne34-20020a1709077ba200b0078e23374ab4si20985399ejc.365.2022.10.24.06.43.10; Mon, 24 Oct 2022 06:43:34 -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=GoOQgGqp; 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 S236141AbiJXNex (ORCPT + 99 others); Mon, 24 Oct 2022 09:34:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236234AbiJXNaJ (ORCPT ); Mon, 24 Oct 2022 09:30:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F750ACA33; Mon, 24 Oct 2022 05:33:31 -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 12EA36125D; Mon, 24 Oct 2022 12:13:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2408DC433D6; Mon, 24 Oct 2022 12:13:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613589; bh=ftzICmIaYa6X+2Y3LTRSb2ARZqMPbOVnX0qX51ONXuM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GoOQgGqpYAACXTO33lAzdSfdfxeBvbAfyXjTG0+3PccdsSkN0gIL5u6WNRxO4cdl3 etsV3lxNey1AJjxcNU/qT968uBUnqm9ClDd288JG8HYWSY5rBlkZHQM/BThYzJxJcm SnrMCS8yOjn5drHk85T9KGb766nyEgc1BfhhevKI= 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.4 187/255] powercap: intel_rapl: fix UBSAN shift-out-of-bounds issue Date: Mon, 24 Oct 2022 13:31:37 +0200 Message-Id: <20221024113009.157135825@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@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?1747576699785906737?= X-GMAIL-MSGID: =?utf-8?q?1747576699785906737?= 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 925b0004a0ed..d5a505f32260 100644 --- a/drivers/powercap/intel_rapl_common.c +++ b/drivers/powercap/intel_rapl_common.c @@ -885,6 +885,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);