vdpa/sfc: fix null pointer dereference

Message ID tencent_A1C68827F89429E24C47E05B63A440E42E05@qq.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series vdpa/sfc: fix null pointer dereference |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS

Commit Message

Weiguo Li Jan. 29, 2022, 5:30 p.m. UTC
  When sva is null, sfc_vdpa_info(sva, ...) will cause a null
dereference. Use SFC_VDPA_GENERIC_LOG() to avoid that.
See macros sfc_vdpa_info and SFC_VDPA_GENERIC_LOG
defined in drivers/vdpa/sfc/sfc_vdpa_log.h for detail.

Fixes: 5e7596ba7cb3 ("vdpa/sfc: introduce Xilinx vDPA driver")

Signed-off-by: Weiguo Li <liwg06@foxmail.com>
---
 drivers/vdpa/sfc/sfc_vdpa.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Weiguo Li Feb. 4, 2022, 11:56 a.m. UTC | #1
The macro sfc_vdpa_info(sva, ...) will invoke sva->logtype_main, 
It'll trigger a NULL dereference when sva is NULL.

This patch fix it.

BTW this patch is not superseded by another one:
 [v2] vdpa/sfc: fix null dereference
 (http://dpdk.org/patch/106720)

They looks alike in title, but deal with different files.

Please don't tag me as superseded again :)
  
Maxime Coquelin Feb. 10, 2022, 2:37 p.m. UTC | #2
Hi,

On 2/4/22 12:56, Weiguo Li wrote:
> The macro sfc_vdpa_info(sva, ...) will invoke sva->logtype_main,
> It'll trigger a NULL dereference when sva is NULL.
> 
> This patch fix it.
> 
> BTW this patch is not superseded by another one:
>   [v2] vdpa/sfc: fix null dereference
>   (http://dpdk.org/patch/106720)
> 
> They looks alike in title, but deal with different files.
> 
> Please don't tag me as superseded again :)
> 

Got it, having commit titles being more specific would help to avoid
that! :)

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
  
Maxime Coquelin Feb. 10, 2022, 3:11 p.m. UTC | #3
On 1/29/22 18:30, Weiguo Li wrote:
> When sva is null, sfc_vdpa_info(sva, ...) will cause a null
> dereference. Use SFC_VDPA_GENERIC_LOG() to avoid that.
> See macros sfc_vdpa_info and SFC_VDPA_GENERIC_LOG
> defined in drivers/vdpa/sfc/sfc_vdpa_log.h for detail.
> 
> Fixes: 5e7596ba7cb3 ("vdpa/sfc: introduce Xilinx vDPA driver")
> 
> Signed-off-by: Weiguo Li <liwg06@foxmail.com>
> ---
>   drivers/vdpa/sfc/sfc_vdpa.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/vdpa/sfc/sfc_vdpa.c b/drivers/vdpa/sfc/sfc_vdpa.c
> index fccdd8c687..53f598facc 100644
> --- a/drivers/vdpa/sfc/sfc_vdpa.c
> +++ b/drivers/vdpa/sfc/sfc_vdpa.c
> @@ -328,7 +328,8 @@ sfc_vdpa_pci_remove(struct rte_pci_device *pci_dev)
>   
>   	sva = sfc_vdpa_get_adapter_by_dev(pci_dev);
>   	if (sva == NULL) {
> -		sfc_vdpa_info(sva, "invalid device: %s", pci_dev->name);
> +		SFC_VDPA_GENERIC_LOG(INFO,
> +			"Invalid device: %s.", pci_dev->name);
>   		return -1;
>   	}
>   

Applied to dpdk-next-virtio/main, with rewording the title and cc'ing
stable.

Thanks,
Maxime
  
Maxime Coquelin Feb. 10, 2022, 3:12 p.m. UTC | #4
On 1/29/22 18:30, Weiguo Li wrote:
> When sva is null, sfc_vdpa_info(sva, ...) will cause a null
> dereference. Use SFC_VDPA_GENERIC_LOG() to avoid that.
> See macros sfc_vdpa_info and SFC_VDPA_GENERIC_LOG
> defined in drivers/vdpa/sfc/sfc_vdpa_log.h for detail.
> 
> Fixes: 5e7596ba7cb3 ("vdpa/sfc: introduce Xilinx vDPA driver")
> 
> Signed-off-by: Weiguo Li <liwg06@foxmail.com>
> ---
>   drivers/vdpa/sfc/sfc_vdpa.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/vdpa/sfc/sfc_vdpa.c b/drivers/vdpa/sfc/sfc_vdpa.c
> index fccdd8c687..53f598facc 100644
> --- a/drivers/vdpa/sfc/sfc_vdpa.c
> +++ b/drivers/vdpa/sfc/sfc_vdpa.c
> @@ -328,7 +328,8 @@ sfc_vdpa_pci_remove(struct rte_pci_device *pci_dev)
>   
>   	sva = sfc_vdpa_get_adapter_by_dev(pci_dev);
>   	if (sva == NULL) {
> -		sfc_vdpa_info(sva, "invalid device: %s", pci_dev->name);
> +		SFC_VDPA_GENERIC_LOG(INFO,
> +			"Invalid device: %s.", pci_dev->name);
>   		return -1;
>   	}
>   

Applied to dpdk-next-virtio/main.

Thanks,
Maxime
  

Patch

diff --git a/drivers/vdpa/sfc/sfc_vdpa.c b/drivers/vdpa/sfc/sfc_vdpa.c
index fccdd8c687..53f598facc 100644
--- a/drivers/vdpa/sfc/sfc_vdpa.c
+++ b/drivers/vdpa/sfc/sfc_vdpa.c
@@ -328,7 +328,8 @@  sfc_vdpa_pci_remove(struct rte_pci_device *pci_dev)
 
 	sva = sfc_vdpa_get_adapter_by_dev(pci_dev);
 	if (sva == NULL) {
-		sfc_vdpa_info(sva, "invalid device: %s", pci_dev->name);
+		SFC_VDPA_GENERIC_LOG(INFO,
+			"Invalid device: %s.", pci_dev->name);
 		return -1;
 	}