Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1895144pxb; Thu, 16 Sep 2021 19:23:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9P5Gjc/auFCleWxkJLN0buvnGucOwgXJrU25dVUpWQnqzf/y7BKXFDU0mSc3dgIONs1dq X-Received: by 2002:a17:906:289a:: with SMTP id o26mr9788149ejd.243.1631845399910; Thu, 16 Sep 2021 19:23:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631845399; cv=none; d=google.com; s=arc-20160816; b=VLK6p4piw8x988+lHf8PzHVbJVCW/N/Ogktdm6ue4DSJU6MkikjPha8YNlpf7SqmDd J9WWU06vrx2D3GOpEt6K02kPFNl2a3TAhzjolRFk5laqmBameGD7BENddNZBPUupCjS9 DxX3Gc96bHXzlnosAPL3nb3NIL68HhBZvRG2eRyaKqJ07UIqYcQVtax2bkTo0isAsVTt SZeywr9Gi2RwupgO5x4FHktvs261gWClRGOep56cvtdrItiuZ83srEHV317rok7uAQK7 6lqGBZZFvEVpZoDRB/QwBwwGI7bkUOgFAWUwzqYGeo4R1V8YIQixd5xxUS38XaJDXHWA htWg== 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=x/b+6ReiyDKwEkokH2kD8tqYYr9ARbqiZjIvobnA4CtddagkrhBhXehwYysvem8mkv Smh1fNInPCBrLKnLqkFVLS7ugQFvg7lrGNTs2dw2TAxBKD8PdCql7Pna9V3PQf0bvatV nSNYljtXVPhXwioIBh/agsAYr7VEdYdBwTUnkP8j1IY0qm3T6h4U2HIo0IfN9R6ViyL2 dnvY6Iqst+1Q70pm1BU+GnY9c1C90c28LIbGJOBCMsAcaalKK5l0spcKK1YHWGpNO0Fy XFAUgacPysTi0nFZRhS/7Erzcn3I5fVP8uPJRo5LDi2dSR8u/IozM671cf4okv4c7O5/ iL6g== 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 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 r2si5230921eda.616.2021.09.16.19.22.56; Thu, 16 Sep 2021 19:23:19 -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=cVx2ttMU; 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 S239607AbhIPRNS (ORCPT + 99 others); Thu, 16 Sep 2021 13:13:18 -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 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; }