From patchwork Mon Oct 24 11:31:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8844 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp431636wru; Mon, 24 Oct 2022 05:44:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7rAY4LRXkRr3jq72SKYu9GSI8BJJktUTfIYKSJE4PjDBAucJNPvKd3qPc5ikxtjlzYhD+v X-Received: by 2002:a17:907:948f:b0:7a7:5fc8:909 with SMTP id dm15-20020a170907948f00b007a75fc80909mr4967084ejc.658.1666615460556; Mon, 24 Oct 2022 05:44:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615460; cv=none; d=google.com; s=arc-20160816; b=LEmC3Q09BOu6C39QPFPMCUnGjN6mkRyGpBTaHMd9zWJJ8xO23eOCuuJTXRcULq7M+j Aqrn881rb4/UfQToKPC+2p6+YFAMQpVK/hDm+jMFb9+1zFz6LTi1wqmKuVs9Jc/48t5w wgxRQ7bXa9Jg64W/nuxvE4iQ0JZxGTuo7yR46GkNSQadcBAdKX8QtRNzucDFuhU3NQQz cVvKB/7BBzcWI5cTQDFd5PRKmaZHqrUfM+yGVRnVlWHUDaswY4g+7rY1bRS5/iXI2gpq 85wJd83f6fCNG97uhQEala2iCTECUC0pk0joFtXx+tmGLBoC61ssFJ9Vwp74pgvKgb8e lbuQ== 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=YgsaH0QHMTWJ38CLHHGXaZ2Gz1hlGvwx8gH/D5BuGpY=; b=bx0lSaQDqGlNQUXXJcfPEix/qP6lodRvKo3Ptb57Og8/W//unao9DYhlHrH9nQ7cgN HPyvzjW7/nlJc+whxfll9Qj0waZi1jBIuZxTKXT+6okTHpqHfHp+sn2/ZiO6qxytkkuH xOEg/BcpS7ZVI0mV8gsFW8WOeLKiN4CIxKXAdOg+XbYWJw2vwr6DC/XyyAGUN6SbQFcx ccu4YNfHEceVkNZ3JRQGZw/GDfP1n8l69tRIYR8xn9a4Yjm7HPHJzT36ksRSWbgR7xud bMwE/A8vc2EZb0qrA7snjLFqcS9XN7E+dTHMTXQac5ymaxwz7ILxO+69nTsC5nwyoiOp U74Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=URM9KukG; 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 c6-20020a05640227c600b00461e3e1a628si1613938ede.110.2022.10.24.05.43.54; Mon, 24 Oct 2022 05:44:20 -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=URM9KukG; 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 S231963AbiJXMiM (ORCPT + 99 others); Mon, 24 Oct 2022 08:38:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234337AbiJXMew (ORCPT ); Mon, 24 Oct 2022 08:34:52 -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 B306F58504; Mon, 24 Oct 2022 05:05:12 -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 4DB0161311; Mon, 24 Oct 2022 12:02:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D272C433D6; Mon, 24 Oct 2022 12:02:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612927; bh=D10J9yBbVDhCPyPeEabyHA9i/KE6B7sbMw0ny/UqgeY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=URM9KukGNMflYMSxV4AYHJM51WBO74L1qcIc199vtWFHX/lL2X0zwMtiYW9v5jS4F YR1TUTwYXF3VWxeJliqJdi+0zlqketSCGpqzkyp/fTsCP1BacNDrz6Z4Ucu0Jvzl8f tITkcTZuguvK5zj5h9zzE02kN1LbtOYHR7Plc+CU= 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.19 172/229] powercap: intel_rapl: fix UBSAN shift-out-of-bounds issue Date: Mon, 24 Oct 2022 13:31:31 +0200 Message-Id: <20221024113004.659711297@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@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?1747572973394575971?= X-GMAIL-MSGID: =?utf-8?q?1747572973394575971?= 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 8cbfcce57a06..ae6721333c0f 100644 --- a/drivers/powercap/intel_rapl.c +++ b/drivers/powercap/intel_rapl.c @@ -1068,6 +1068,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);