From patchwork Mon Sep 20 16:40:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 514351 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp2303002jao; Mon, 20 Sep 2021 11:05:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOKZLFSqkerzdQLjT4cw9ofguLAU6/VP0Dfq6N/WDIJL6UW+O482uOAU0a48O4pWOqpVjs X-Received: by 2002:a05:6e02:1e0d:: with SMTP id g13mr7828943ila.265.1632161150900; Mon, 20 Sep 2021 11:05:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632161150; cv=none; d=google.com; s=arc-20160816; b=ecH+/9frezw+eUAGz9/55FBqiXuHmb2sBXGMZRnoj2Zp8Ump3M2UZiKlnb5JSsHaAd L0qOZusjZ8NbZycnlX7ZdmXsvwI9k7yLGislWS62R850y8OEIAMICVAGyn+qUhS+N4o7 Ck86Esa6oYrRjIHYrBYlSFXOpiIVq+kEu4UZr3FnNeURYwFIpoH9ebJUHkfUmj9zB4my IZQP7BHITiQ4CYNqakLBkq/zg3h/AaDXCUE60h4NCCsoMxNEP0pIOz6MktIq4YfdTqbz 2EjqgqA9MTESyXlUl1lCFUfiU5Mn9SO+1+4yHN4NAT1TRxtlRTbziPFCwQpZWCW3yMHy C+Wg== 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=kDTuQA7ks3xmtiPuLNuScHvJHxac63su0nuT1jmi2q8=; b=D6Qq8zCH0cTYwOCkzff3/eoOqvRh8jZbtboUBGgkO9t5CZEneLCvuneWGjHyo64+LO JxtuVmlaNfUMSA4n2E7nIy4KR4isiVTcKc/pChksjL2/1EoURB6rOWivAQaFPjHIGP/K vVe3bFbMOUMhXK0pIzIK7ccuggwfeGlhqexlv1T78/TXiiF0Fnia/UGP5ysSBSMNGwaU G6ofKyhHD/7/u4oQZfYAVzKIYMxsjmf2rcTv3dFiJHM2iUoN5EGgyyBJIRCAqOd1UKKS u1KxhuxO54xmjtoC4Tl1rbmKiyI9cvtqNbnwbIPzCA/XDQWzsS/4Y0r+p9zZCaHstEmR 16Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kmk7rfT6; 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 n13si13723864ilo.25.2021.09.20.11.05.50; Mon, 20 Sep 2021 11:05:50 -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=kmk7rfT6; 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 S1358382AbhITSGZ (ORCPT + 11 others); Mon, 20 Sep 2021 14:06:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:58224 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356974AbhITSCg (ORCPT ); Mon, 20 Sep 2021 14:02:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8ED2663230; Mon, 20 Sep 2021 17:16:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158189; bh=OtYyeNVEmiHOkCZyO54XEpO15PXrjbdloWEzf05+4KI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kmk7rfT6XpU2pXb3xd6bJ7KNwrX09EZHimVC0X+eQ0et8qN2SBy+7W0NuOr16VCdb PZHcH1sSVWdDEjjlOUKOEd1R1u621n59irHCA929ae+3M04JEiStiamT0McFXUoxNf Cfe2Q9ppazsxEaIkrsqxv/oJ5KgiG9ZIYP7Z36qA= 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.4 014/260] soc: qcom: aoss: Fix the out of bound usage of cooling_devs Date: Mon, 20 Sep 2021 18:40:32 +0200 Message-Id: <20210920163931.606307946@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@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 @@ -472,12 +472,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); @@ -493,12 +493,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; }