From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 32F47C531DC for ; Fri, 23 Aug 2024 08:44:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:CC:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=7Cl5LvNOiyDRuJVxJHLWr/LUmRasTAOdqypamW4Uapo=; b=06TvfGN0G201l3rBofunTtiRqe 0j7jHKDxLQmoCgMtYsC39eDfy7bsyWLgq4qNTYShMevcX+VjISHJCNK8iEX0hV+5dUSzBD9Exa6Y0 MoMmi+O9OpV+Alyww8A3WCcB3nMk02hK+e6VDqeU/qTrL1deIEFw98Qa7BnTmpJk+S7HpqGVkp0Bl X8CDJGC3CLXk9rg2QeD92Jy7PRdRjM+5dMUeLIkWVDN5EYRER7JGI6g9W2uolFfByAOwzZTySw7Y0 3e0O7Bx9/EWjjhi4iXZN8NYmP5szN9rQQQnQ08GdaxcCBV1OSuB0L7UPPdwLpNvDZH5N3CqwaaxH+ OLNIarcg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1shPuO-0000000FwLs-2qCv; Fri, 23 Aug 2024 08:44:36 +0000 Received: from frasgout.his.huawei.com ([185.176.79.56]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1shPp4-0000000Fuhu-121N for linux-arm-kernel@lists.infradead.org; Fri, 23 Aug 2024 08:39:08 +0000 Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Wqtgq2hDVz6K8h6; Fri, 23 Aug 2024 16:35:51 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 023461400DD; Fri, 23 Aug 2024 16:39:00 +0800 (CST) Received: from localhost (10.203.177.66) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 23 Aug 2024 09:38:59 +0100 Date: Fri, 23 Aug 2024 09:38:58 +0100 From: Jonathan Cameron To: Huisong Li CC: , , , , , , Subject: Re: [PATCH v2 3/6] soc: hisilicon: kunpeng_hccs: Add the check for base address and size of shared memory Message-ID: <20240823093858.00007047@Huawei.com> In-Reply-To: <20240823031059.32579-4-lihuisong@huawei.com> References: <20240718071134.31155-1-lihuisong@huawei.com> <20240823031059.32579-1-lihuisong@huawei.com> <20240823031059.32579-4-lihuisong@huawei.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.203.177.66] X-ClientProxiedBy: lhrpeml100001.china.huawei.com (7.191.160.183) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240823_013906_736717_0F2D368C X-CRM114-Status: GOOD ( 20.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, 23 Aug 2024 11:10:56 +0800 Huisong Li wrote: > If the shmem_base_addr from PCCT is zero, hccs_register_pcc_channel will > return success. And then driver will access to illegal address when send > PCC command. In addition, the size of shared memory used for communication > between driver and platform is fixed, namely 64 Bytes which is > unchangeable. So add the verification for them. > As with previous, make it clear if this hardening or fix fix to catch a problem on shipping hardware (I assume not, but you never know!) A comment on existing code inline. Not a suggestion for a change in this series, but maybe for the future. There are a lot of goto err_mbx_channel_Free in here already and this patch adds another. The cleanup there is trivial so DEFINE_FREE() and __free usage will make this code quite a bit nicer to read. > Signed-off-by: Huisong Li Reviewed-by: Jonathan Cameron > --- > drivers/soc/hisilicon/kunpeng_hccs.c | 24 +++++++++++++++--------- > 1 file changed, 15 insertions(+), 9 deletions(-) > > diff --git a/drivers/soc/hisilicon/kunpeng_hccs.c b/drivers/soc/hisilicon/kunpeng_hccs.c > index 6e88f597f267..6055e5091cbd 100644 > --- a/drivers/soc/hisilicon/kunpeng_hccs.c > +++ b/drivers/soc/hisilicon/kunpeng_hccs.c > @@ -170,15 +170,21 @@ static int hccs_register_pcc_channel(struct hccs_dev *hdev) > goto err_mbx_channel_free; > } > > - if (pcc_chan->shmem_base_addr) { > - cl_info->pcc_comm_addr = ioremap(pcc_chan->shmem_base_addr, > - pcc_chan->shmem_size); > - if (!cl_info->pcc_comm_addr) { > - dev_err(dev, "Failed to ioremap PCC communication region for channel-%u.\n", > - hdev->chan_id); > - rc = -ENOMEM; > - goto err_mbx_channel_free; > - } > + if (!pcc_chan->shmem_base_addr || > + pcc_chan->shmem_size != HCCS_PCC_SHARE_MEM_BYTES) { > + dev_err(dev, "The base address or size (%llu) of PCC communication region is invalid.\n", > + pcc_chan->shmem_size); > + rc = -EINVAL; > + goto err_mbx_channel_free; Worth considering for the future: Maybe a DEFINE_FREE for pcc_mbox_free_channel) makes sense, though if you do you should only assign cl_info->pcc_chan after all possible error paths. > + } > + > + cl_info->pcc_comm_addr = ioremap(pcc_chan->shmem_base_addr, > + pcc_chan->shmem_size); > + if (!cl_info->pcc_comm_addr) { > + dev_err(dev, "Failed to ioremap PCC communication region for channel-%u.\n", > + hdev->chan_id); > + rc = -ENOMEM; > + goto err_mbx_channel_free; > } > > return 0;