Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2521417pxj; Mon, 10 May 2021 05:07:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYdpiIUCZcHjoIH5K3paJzBnRaKFeERLkrjBVlAMTuHWKdUAUjCOlOpJvzVEO0PmeVhh4f X-Received: by 2002:a92:6f11:: with SMTP id k17mr21570441ilc.200.1620648325892; Mon, 10 May 2021 05:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620648325; cv=none; d=google.com; s=arc-20160816; b=NINl8n128wNuj+jsCwrJR7jY4qJ11RVimo3UiftZa0/xe5gyXH4jtz6jspdvtLQjNa +FvCdm27LT99dgeQf5YGCWnM/ygXBuncWB2YiPSGv/icZh086RUatQ5yhrR+jqyde6s7 EbYbaR4rxX/mJ8hdNaNv26sxHU6U1ExqJM4R77HuHWskJzdqUfMmpMtGkGmQphN/jn8T H0o1a9oeks4RPLhNeBKMMQkC8hiSVXLJDhcX/2nq5xNZBmx81zpTOnbpsfyBxjwagUrF EpYej5njiv4pBtZN9qbFmebTqaCjqeQxvJGb6zcWgxFVuJoJw4ih4F8GAWUvAfE6ThQN b2bA== 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=zB3intllfWX2dTLFoD3QaMyT2UaK6KKMLS5CG34IPYU=; b=Aw0aiiZvsPBhcfO89AFy92XHhLMr174pmVXHhgrRr43AO9/jH5RnF5CaUyulV2wXR1 EyMRxpU6DAvF5geV6tbf7JbkcV4D6nqRnbI7rr2RsO3m7lna6I73CAYtLFWi0p2vNPlK EjskpXgwA5vxahxJ0P1HeQzwkK6DVtuq+LRhLInutKaAx2zWwu6/6Jm1IKk8mZLBwc31 u7HPkGVQNqxuL+IUjSeAUTXAd1NhT548MrqChlX+VwTyhSZu2Q4topym3QfFzTvDmiLp KLmVR6+YVBRYduEzXdomZ44nEbuVGz/H9RP+lny6rh3IKoSozuSeOCZ6SDsHDiRgPK0Z lqfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oAdY72uB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m20si3516454jat.70.2021.05.10.05.05.12; Mon, 10 May 2021 05:05:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oAdY72uB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S244570AbhEJL7X (ORCPT + 99 others); Mon, 10 May 2021 07:59:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:46278 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235952AbhEJLHD (ORCPT ); Mon, 10 May 2021 07:07:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B812261582; Mon, 10 May 2021 10:57:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620644233; bh=ZhuCGbi99ueUfGcvZCo8L1Za/9MQihnuSfx3f9Jvur4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oAdY72uBhswupxGp/ahgwptRcaCXfwCnLORzC3lNvhIm5AyyumuQQIihK4HQlbl+P 4ebozICE7SdX0LseeiGSUhgMi3e/BnpUzQcOE0UWtxZFDWJDOd+ixXqM3XxU9nVLwR oA16zztrcFLE7nmDTJBe9/HualqPC8ZWAjFNQB3k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, brian-sy yang , Michael Kao , Lukasz Luba , Daniel Lezcano Subject: [PATCH 5.11 341/342] thermal/drivers/cpufreq_cooling: Fix slab OOB issue Date: Mon, 10 May 2021 12:22:11 +0200 Message-Id: <20210510102021.382023433@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102010.096403571@linuxfoundation.org> References: <20210510102010.096403571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: brian-sy yang commit 34ab17cc6c2c1ac93d7e5d53bb972df9a968f085 upstream. Slab OOB issue is scanned by KASAN in cpu_power_to_freq(). If power is limited below the power of OPP0 in EM table, it will cause slab out-of-bound issue with negative array index. Return the lowest frequency if limited power cannot found a suitable OPP in EM table to fix this issue. Backtrace: [] die+0x104/0x5ac [] bug_handler+0x64/0xd0 [] brk_handler+0x160/0x258 [] do_debug_exception+0x248/0x3f0 [] el1_dbg+0x14/0xbc [] __kasan_report+0x1dc/0x1e0 [] kasan_report+0x10/0x20 [] __asan_report_load8_noabort+0x18/0x28 [] cpufreq_power2state+0x180/0x43c [] power_actor_set_power+0x114/0x1d4 [] allocate_power+0xaec/0xde0 [] power_allocator_throttle+0x3ec/0x5a4 [] handle_thermal_trip+0x160/0x294 [] thermal_zone_device_check+0xe4/0x154 [] process_one_work+0x5e4/0xe28 [] worker_thread+0xa4c/0xfac [] kthread+0x33c/0x358 [] ret_from_fork+0xc/0x18 Fixes: 371a3bc79c11b ("thermal/drivers/cpufreq_cooling: Fix wrong frequency converted from power") Signed-off-by: brian-sy yang Signed-off-by: Michael Kao Reviewed-by: Lukasz Luba Cc: stable@vger.kernel.org #v5.7 Signed-off-by: Daniel Lezcano Link: https://lore.kernel.org/r/20201229050831.19493-1-michael.kao@mediatek.com Signed-off-by: Greg Kroah-Hartman --- drivers/thermal/cpufreq_cooling.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/thermal/cpufreq_cooling.c +++ b/drivers/thermal/cpufreq_cooling.c @@ -123,7 +123,7 @@ static u32 cpu_power_to_freq(struct cpuf { int i; - for (i = cpufreq_cdev->max_level; i >= 0; i--) { + for (i = cpufreq_cdev->max_level; i > 0; i--) { if (power >= cpufreq_cdev->em->table[i].power) break; }