Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9555162pxu; Mon, 28 Dec 2020 21:10:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJymUmo+7uZRae0Tw1dzQwmeRmKI1BNygdHPQxkdDZyoj+pEycQyO+4avz6IPdD7HwSHBPlg X-Received: by 2002:a17:906:3593:: with SMTP id o19mr43614442ejb.377.1609218652735; Mon, 28 Dec 2020 21:10:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609218652; cv=none; d=google.com; s=arc-20160816; b=ot0GyKuEcu+G662opv+UJt9zUipAZd5UKUtmZ/uuRVqffj4VlEOYyiL31GFUwx3nmM ktsumwBX1A0Fckc297WTamnW95J3JRn1oRaZpuLDkBEMTVMNa7E+3TIRp7F4XvUt4wAe j/d/OezLWW6wcfuWndgxJOSS/gCR/9ORxfytiOA6aLsOhGce3t87dlmNsX7u9fajm49+ /8VEPINDQqxYOJVfxGzbIQLgZxKOHKHyC/hLrfqLnSZJMj03GPmu0LXS5EFhCHMo6Do/ TTKJ+TywQgJwzrxuP8XTWAS0S+59bY/c5/glwkVsjJ6IghXUAU1ZtDPA3+h3cWVt4Bv+ fYPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=iA5qAlvpPy7EOVE6zYq0ZyKZcOo9iLXMHhibz/kd41o=; b=wJp0RdI9PGlwLNUB9d9agJMOTdQM4ymfmb+/vw7fQkap+FRl62Erxn+LDwVBtpJTnK HtcI5uaObgKjphgEOVvrfq3mVGsI7nEF5QDeLsbHEVi6nQHnjUDLQ1dWxnWEZvjZTlIl H73fbgiE+VYBMSY7vFlrfachVEPpdsMwX+ue40aDeBnfkFSHWzt3veOvmIlNjlEsEYJG 4Uf4Loz+ubAULqq8EoW4P8dYOTS4zAsdCbbf4GFdrDJDWH30ArFQTQy/jvhLcOLEA45j W2y0NJDqvb/WW7aesQsj2nEZcZ//wx4T8MSMXL4pPLFRhT60b3oIaoZRcXRtPvTSe9GO N9FA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 97si21478281edr.29.2020.12.28.21.10.30; Mon, 28 Dec 2020 21:10:52 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726021AbgL2FJh (ORCPT + 99 others); Tue, 29 Dec 2020 00:09:37 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:44775 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725967AbgL2FJg (ORCPT ); Tue, 29 Dec 2020 00:09:36 -0500 X-UUID: e4301387693b4638b66833880f68d291-20201229 X-UUID: e4301387693b4638b66833880f68d291-20201229 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.14 Build 0819 with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 401845018; Tue, 29 Dec 2020 13:08:52 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs02n2.mediatek.inc (172.21.101.101) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 29 Dec 2020 13:09:37 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 29 Dec 2020 13:09:36 +0800 From: Michael Kao To: , , Zhang Rui , Daniel Lezcano , , CC: Eduardo Valentin , Rob Herring , Mark Rutland , Matthias Brugger , , , , , , brian-sy yang Subject: [PATCH v2] thermal: cpufreq_cooling: fix slab OOB issue Date: Tue, 29 Dec 2020 13:08:31 +0800 Message-ID: <20201229050831.19493-1-michael.kao@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-TM-SNTS-SMTP: 89869AB40C5636F00832BEFA7C75FECE2ED5AC7D82557EE0D66B7497DA6FFB252000:8 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: brian-sy yang 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 --- Changes from v1: - add fixes tag - add reviewed-by drivers/thermal/cpufreq_cooling.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/thermal/cpufreq_cooling.c b/drivers/thermal/cpufreq_cooling.c index cc2959f22f01..fb33b3480a8f 100644 --- a/drivers/thermal/cpufreq_cooling.c +++ b/drivers/thermal/cpufreq_cooling.c @@ -123,7 +123,7 @@ static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_cdev, { 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; } -- 2.18.0