[PATCH] scsi: qedf: Fix potential null pointer dereference

Liao Chen posted 1 patch 2 months, 2 weeks ago
There is a newer version of this series
drivers/scsi/qedf/qedf_main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] scsi: qedf: Fix potential null pointer dereference
Posted by Liao Chen 2 months, 2 weeks ago
qedf is checked to be null in this if branch, accessing its member will
cause a null pointer dereference. Fix it by passing a direct NULL into
the error function.

Fixes: 51071f0831ea ("scsi: qedf: Don't process stag work during unload and recovery")
Signed-off-by: Liao Chen <liaochen4@huawei.com>
---
 drivers/scsi/qedf/qedf_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c
index 4813087e58a1..9d4738db0e51 100644
--- a/drivers/scsi/qedf/qedf_main.c
+++ b/drivers/scsi/qedf/qedf_main.c
@@ -4021,7 +4021,7 @@ void qedf_stag_change_work(struct work_struct *work)
 	    container_of(work, struct qedf_ctx, stag_work.work);
 
 	if (!qedf) {
-		QEDF_ERR(&qedf->dbg_ctx, "qedf is NULL");
+		QEDF_ERR(NULL, "qedf is NULL");
 		return;
 	}
 
-- 
2.34.1
Re: [PATCH] scsi: qedf: Fix potential null pointer dereference
Posted by Bart Van Assche 2 months, 1 week ago
On 9/12/24 8:36 PM, Liao Chen wrote:
> qedf is checked to be null in this if branch, accessing its member will
> cause a null pointer dereference. Fix it by passing a direct NULL into
> the error function.
> 
> Fixes: 51071f0831ea ("scsi: qedf: Don't process stag work during unload and recovery")
> Signed-off-by: Liao Chen <liaochen4@huawei.com>
> ---
>   drivers/scsi/qedf/qedf_main.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c
> index 4813087e58a1..9d4738db0e51 100644
> --- a/drivers/scsi/qedf/qedf_main.c
> +++ b/drivers/scsi/qedf/qedf_main.c
> @@ -4021,7 +4021,7 @@ void qedf_stag_change_work(struct work_struct *work)
>   	    container_of(work, struct qedf_ctx, stag_work.work);
>   
>   	if (!qedf) {
> -		QEDF_ERR(&qedf->dbg_ctx, "qedf is NULL");
> +		QEDF_ERR(NULL, "qedf is NULL");
>   		return;
>   	}

I think it would be better to remove the if-statement and the
if-statement body since qedf cannot be NULL in this function.

Thanks,

Bart.
Re: [PATCH] scsi: qedf: Fix potential null pointer dereference
Posted by liaochen (A) 2 months, 1 week ago
On 2024/9/13 11:36, Liao Chen wrote:
> qedf is checked to be null in this if branch, accessing its member will
> cause a null pointer dereference. Fix it by passing a direct NULL into
> the error function.
> 
> Fixes: 51071f0831ea ("scsi: qedf: Don't process stag work during unload and recovery")
> Signed-off-by: Liao Chen <liaochen4@huawei.com>
> ---
>   drivers/scsi/qedf/qedf_main.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c
> index 4813087e58a1..9d4738db0e51 100644
> --- a/drivers/scsi/qedf/qedf_main.c
> +++ b/drivers/scsi/qedf/qedf_main.c
> @@ -4021,7 +4021,7 @@ void qedf_stag_change_work(struct work_struct *work)
>   	    container_of(work, struct qedf_ctx, stag_work.work);
>   
>   	if (!qedf) {
> -		QEDF_ERR(&qedf->dbg_ctx, "qedf is NULL");
> +		QEDF_ERR(NULL, "qedf is NULL");
>   		return;
>   	}
>   
gentle ping

Thanks,
Chen