From patchwork Thu Sep 16 15:56:23 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: 513015 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp1411719jao; Thu, 16 Sep 2021 10:06:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsyO+Nm0/GM8RoeNZkFBWquNFf7kC84JDSaOe9geXBhcNwI/vy2pFSYyIa15M+rIbvpt5h X-Received: by 2002:a92:b705:: with SMTP id k5mr4698655ili.224.1631812001700; Thu, 16 Sep 2021 10:06:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631812001; cv=none; d=google.com; s=arc-20160816; b=dosXMfo2ivUaWtweoKfWMqn9nptn7nIyCTroUqaoXl6CiIumptt3XrOEEmWG/rUxob QejWNHJxSWerwuB0BEYiepbrkKXpclvjNLN5zPpIM9C4OAerhQ5UXh0cuBFFypIUHcx/ x4+WRlQ7tMArSRjFmsC92FyTM7HHmO4UJWG439Xsclz4pBtEO/1711X1KwZ6Xde/2IPg 7Jyy6l7b6tdgXFPAAGfnOl84V+31ys5a1+kTWM6jB1QVn48m1R8kgP0yLHqt1f384vQM vfgq7NMyY9MQuz3l0f7vqi3XeKN6scE27osw4DY8w3Byjv7s7le2cYvcz9FqQ3coqZPj jMHw== 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=DSepPkNNh58E1ZYFal6ur5e9dXSFD6vSkTbAeAvkev8AT8rFAeOaKPIzNzUPgKGiNI 8GIzu4ym614avzTpLDNY9V0xDkd07TTFlNNWJvlkpi7YUwM3E83dXv8GrTVTYFjwehhk OZbqJ/PF3MF3Hu/slburbv5YM6ZBRhWno+qeLbzbxxRL8O1CHkK/QK8Ec7sQ/m/rc36U XuPT5RGt4KY1NALkh5ZWw1H4izwAzh9ft4cTBvg26JnMxM31IZEqOfBzlpIf5CBuw6Tt hJwQeVuobvYLYXeM7kz6swowdBBYKwnhayPghqQOs1w7nB2TShOgCGRVEclpNhj5O+Qv +8Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cVx2ttMU; 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 m33si2811340jaf.66.2021.09.16.10.06.41; Thu, 16 Sep 2021 10:06:41 -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=cVx2ttMU; 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 S1349947AbhIPRH7 (ORCPT + 11 others); Thu, 16 Sep 2021 13:07:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:36054 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244810AbhIPRF5 (ORCPT ); Thu, 16 Sep 2021 13:05:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 702C161929; Thu, 16 Sep 2021 16:35:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631810145; bh=9Il0Hw1D98NLQ7HT7OgkMPuWKBxbTH4IlNe5LuYf0rQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cVx2ttMUL0t8at7Ojx2TjffzW25eifDjpdort0nTAIw85QtGsQt4dMv4n8EUI7nvm 5H8gu0iTxzyqUbi6Rx5YBROCOmMqSxtLM8iSUi42yiuoxciqBsuZNYxO0HpRlAkwpp 2GvBlRTEgFe7c2IbTaOXgjHqfn/WtAQ5LwSAqgxQ= 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.14 034/432] soc: qcom: aoss: Fix the out of bound usage of cooling_devs Date: Thu, 16 Sep 2021 17:56:23 +0200 Message-Id: <20210916155811.973938127@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155810.813340753@linuxfoundation.org> References: <20210916155810.813340753@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; }