From patchwork Thu Sep 16 15:56:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 512994 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp1374628jao; Thu, 16 Sep 2021 09:29:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVp3WQyaC+SqKpXX6wwDXWn8VqjTHFw3zKNKR840bOsWijv99/uLIyAF5OymX5GWbIOp41 X-Received: by 2002:a17:906:2f15:: with SMTP id v21mr7249814eji.444.1631809797021; Thu, 16 Sep 2021 09:29:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631809797; cv=none; d=google.com; s=arc-20160816; b=GqqUkhfYsUs75VyeRr24hNt4pTIIsL+6QVjuRDzENvFDvMyDR3lmM1/4PJuonoDXO3 wtLAaeHZpn+JgAFYis2vj+W+IbKCk73YafoPFZND0PSFvjTExH6kfyoHsNZdC28tVBKC U5cpzGkRMI2R3/+dvTZaUkaMGA4tOdor0WQBNKbNEaesP8mxhKE36ZfuxZyD8e+8wvhi 0ThrbdPBasM2ToBHy27a0bc5WUgEo4abAgUxZT/MHY6M2tA4rZlgOFbG1goBFUh5mH2a Hlp0GnojqmW2E4rBLFDZOVClo/TCkU1YuNE07EeDqybSaYpe1J+QYNKHB7mEg1EY5XbQ i9aw== 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=VnxPhnnxHYDMHAAOOQQexutbWfYrnkOO+z/JyIvmxUlLvrmYVAYyw/uetUM3hUlchq EQzO3dE5PtLcUn1FFUl61h9e+zD7ysmfkFKfB9/g9hvob+Ds2pachiNLGyY+gxEqd9ce l4vaXiQ6KUuCxwnH+FGDQ1IwbLRS2jikZ8GsrbpERDnK6l+aJHorRuZ+VZwO9VSRPGO5 vAZ0UkGYKi2Hw0MSmwzU7qKiCvpuaxJx5Ax1aLI2X6pmnnQpYZ5AQaTiH/10EcJksVsc P5B63TYyxBD6TOyzJ4MbrZyz+SyzPxOVufU6kxIsFCYyBCQPJPDDtWxrZJIWVRbkNsYQ UvmA== 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 stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 y22si4981692edm.232.2021.09.16.09.29.56; Thu, 16 Sep 2021 09:29:57 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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 stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S242301AbhIPQaz (ORCPT + 11 others); Thu, 16 Sep 2021 12:30:55 -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 Precedence: bulk List-ID: X-Mailing-List: stable@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; }