]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
soc: hisilicon: kunpeng_hccs: Add the check for base address and size of shared memory
authorHuisong Li <lihuisong@huawei.com>
Wed, 28 Aug 2024 10:49:53 +0000 (18:49 +0800)
committerWei Xu <xuwei5@hisilicon.com>
Mon, 14 Oct 2024 08:54:48 +0000 (08:54 +0000)
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 hardening code.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Wei Xu <xuwei5@hisilicon.com>
drivers/soc/hisilicon/kunpeng_hccs.c

index 6e88f597f2676515230bba6ff0d0124e283ee396..6055e5091cbd06668f87dac4470a696707e7294e 100644 (file)
@@ -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;
+       }
+
+       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;