Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1544542pxb; Thu, 16 Sep 2021 09:36:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6snVp1fOq2g8Gt2s7Crb1flGGmycwdN/dTT3HXuqziARUKRyT1JepP4D+wtX2xghWLRgJ X-Received: by 2002:a05:6638:35a9:: with SMTP id v41mr5127876jal.98.1631810217558; Thu, 16 Sep 2021 09:36:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631810217; cv=none; d=google.com; s=arc-20160816; b=CoT6vtHwTYZFiMAQmxVvcBx14wbxtpmwwJHiwJ5RZzEaT+uErDPU4N+nbD+9o86V4E bFKtboIPlDDbYcsRelpqOrcWc7qAzLbndVn2Cvam+6H9kzPAdk6srZySGjMvTtzhyPMI ZOm8vPs7LakRt/UWzOCMtC3Fq3bBz75LohKFzekjfGAWUtKAsOtO2XJfjoxQb95QHj27 7MIYNYYI65v2rUKYXRm2qUEkNYzV3OBefTaczdyVSXeleEt2DO3CkBXqVlWLRjt8hPgc DpCsrJTzdhs1lqOez5z2Vl1ENAxyOIzPxiEcBkNqT/4VDJcJK+zz2moDMV87xk3C0wPI 7h6A== 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=/qjFIn4ilt/NtUkcEYFWsZsphnKNd9i8eP45RpcRHvQ=; b=Sp6MkseH2fLgo097CeDAYbV1DiPEEdPsO3hGy1HUtqmfNuBzE+vksCvQR/7HeeO33y JG9ueHWA1uvQMsI+fy5pq0a4Fv+KWXaIY0tvfzUB/Mjkih60DlktdeIXU0iHkm4Ce5Tp I1NeOtwkcOQfY5uFGCX4oU2jLwHTfXmpEo7Ldu4aWN4d5Hivs2wb51Jf7r84hVirj0WF 0cy0z27OmnZHi+3Bagn37yvd/Sjt5kaCsgP/+Md8d6VijcJY9O7BrLcYcqRRp7d9S+md fHN1FnXEu+kCS9D9hos9SRAkIZGtn+7QPSwZT0sFdKTJR9TIoXQgz4jnG+tvzR6CNgGz 25Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TAc2NMgU; 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 y15si1849281ilv.67.2021.09.16.09.36.43; Thu, 16 Sep 2021 09:36:57 -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=TAc2NMgU; 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 S243534AbhIPQgW (ORCPT + 99 others); Thu, 16 Sep 2021 12:36:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:36998 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234178AbhIPQ2r (ORCPT ); Thu, 16 Sep 2021 12:28:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9BA7D61359; Thu, 16 Sep 2021 16:18:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631809091; bh=9Il0Hw1D98NLQ7HT7OgkMPuWKBxbTH4IlNe5LuYf0rQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TAc2NMgUrij8uB2g7SNntdtUe5GMSmTfhepew496Z3BmUeoygI8Qc5t/JccMJG16n FSVF9yS9q1HRyBT9aBCC8yt6C/LMZbctOMgP003GSP9ZnZSJI0Dc7mj4A1Lh1Znzn1 zlva1JSbOGbZF9AA1NHGIvpgEYQVM3kTNQJfJcGo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Manivannan Sadhasivam , Bjorn Andersson Subject: [PATCH 5.13 027/380] soc: qcom: aoss: Fix the out of bound usage of cooling_devs Date: Thu, 16 Sep 2021 17:56:24 +0200 Message-Id: <20210916155804.891369289@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155803.966362085@linuxfoundation.org> References: <20210916155803.966362085@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: Manivannan Sadhasivam commit a89f355e469dcda129c2522be4fdba00c1c74c83 upstream. In "qmp_cooling_devices_register", the count value is initially QMP_NUM_COOLING_RESOURCES, which is 2. Based on the initial count value, the memory for cooling_devs is allocated. Then while calling the "qmp_cooling_device_add" function, count value is post-incremented for each child node. This makes the out of bound access to the cooling_dev array. Fix it by passing the QMP_NUM_COOLING_RESOURCES definition to devm_kzalloc() and initializing the count to 0. While at it, let's also free the memory allocated to cooling_dev if no cooling device is found in DT and during unroll phase. Cc: stable@vger.kernel.org # 5.4 Fixes: 05589b30b21a ("soc: qcom: Extend AOSS QMP driver to support resources that are used to wake up the SoC.") Signed-off-by: Manivannan Sadhasivam Link: https://lore.kernel.org/r/20210629153249.73428-1-manivannan.sadhasivam@linaro.org Signed-off-by: Bjorn Andersson Signed-off-by: Greg Kroah-Hartman --- drivers/soc/qcom/qcom_aoss.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/drivers/soc/qcom/qcom_aoss.c +++ b/drivers/soc/qcom/qcom_aoss.c @@ -476,12 +476,12 @@ static int qmp_cooling_device_add(struct static int qmp_cooling_devices_register(struct qmp *qmp) { struct device_node *np, *child; - int count = QMP_NUM_COOLING_RESOURCES; + int count = 0; int ret; np = qmp->dev->of_node; - qmp->cooling_devs = devm_kcalloc(qmp->dev, count, + qmp->cooling_devs = devm_kcalloc(qmp->dev, QMP_NUM_COOLING_RESOURCES, sizeof(*qmp->cooling_devs), GFP_KERNEL); @@ -497,12 +497,16 @@ static int qmp_cooling_devices_register( goto unroll; } + if (!count) + devm_kfree(qmp->dev, qmp->cooling_devs); + return 0; unroll: while (--count >= 0) thermal_cooling_device_unregister (qmp->cooling_devs[count].cdev); + devm_kfree(qmp->dev, qmp->cooling_devs); return ret; }