From patchwork Thu Sep 16 15:56:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 512973 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp1350869jao; Thu, 16 Sep 2021 09:04:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhCZziferFlO/aicXoP5irbbsU7pANmK3+MKNHUG2nAeXsS+7XsOXAji2ce3ETUySo9tjI X-Received: by 2002:a05:6e02:1212:: with SMTP id a18mr4475645ilq.68.1631808289371; Thu, 16 Sep 2021 09:04:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631808289; cv=none; d=google.com; s=arc-20160816; b=c1DDm5/yxaZfCBCC00zkw1FZyJJ1YnYAfy7x5ouQp1t28uPU/vDvzYRQcxDVwnBMLF k9slXaDdOfEWL7dIW3jHy1MdUJ4awRhWJoaZbj8vOfARv+zTjOkoCfOuaHv2Br+uKVzr 00/t/u5WXH5od8BJ5PhwgWvqdnT23J6EhySjmQKpAsev3GtGwQhojVXUQEqRjp9BvY7U 5jLZ/airKTRji2K0i54oJt35G6t58LFdI74pg2QsuaTAFW0IWXQo/L3dmJzpOTXQAhJS C5tB4us4f7Zv3pUl9lQmhkCubKKmJSKy2AFu/MovjLBzyVo8bazL78EQJccQVtzNaIYr Vuag== 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=lSPqSuLgI31jbeqt4UU8adacaNv1Rl+8NTw3EiP3lPxQsmkKeXG0vsIbPuL64MKy6B HPW5vp0Krm0DiRIVXoUeFbPMXI+rFLGiKj4SawR4rvLJVvlvI90EYGF5Lx0qiRr5d5YG uzXc2o7kaaiFp3FOgwDYOky/yTdysPeooA/8RiXmJl12y8oo5YvfscR8cKqdQf0Pi+HU UsZwkEdOeEDsbKF65gM6I7CCVSOiFdUb0CGlejYJPb4f2PgeR6tyuJ6GSSFj7JWJqfgE ZZ1uOQrIvd7RCkRU9PePqCkUtQ1B1aQr4ldpgi3jwyWAi8PhM9yFzbmGX2C4hAivt4/+ ROIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=emKoic8e; 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 b18si2957680ioz.23.2021.09.16.09.04.49; Thu, 16 Sep 2021 09:04:49 -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=emKoic8e; 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 S240617AbhIPQGE (ORCPT + 11 others); Thu, 16 Sep 2021 12:06:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:44956 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240635AbhIPQFs (ORCPT ); Thu, 16 Sep 2021 12:05:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 175EB61251; Thu, 16 Sep 2021 16:04:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808267; bh=9Il0Hw1D98NLQ7HT7OgkMPuWKBxbTH4IlNe5LuYf0rQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=emKoic8eMmtzzrPNIB+ADiIJxmolILvmDr3EoEFfSAYM/3IvJscQazIP2kSXxXCv6 Qnp2OP7aRgvM2NcDNHXgPcc/35IfMXZOt/wmkFwv5GIcAR7KYIzcA8V+icMI0ansOs mLSEBFJWg6qOfgcPmUJY+KWcn9KA1DLbDveBXNLQ= 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.10 023/306] soc: qcom: aoss: Fix the out of bound usage of cooling_devs Date: Thu, 16 Sep 2021 17:56:08 +0200 Message-Id: <20210916155754.727259705@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@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; }