* [PATCH] scsi: libfc: Fix potential NULL pointer dereference in fc_lport_ptp_setup
@ 2023-10-11 13:03 Wenchao Hao
2023-10-13 15:41 ` Simon Horman
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Wenchao Hao @ 2023-10-11 13:03 UTC (permalink / raw)
To: Hannes Reinecke, James E . J . Bottomley, Martin K . Petersen,
Richard Cochran, linux-scsi
Cc: linux-kernel, netdev, louhongxiang, Wenchao Hao
fc_lport_ptp_setup() did not check the return value of fc_rport_create()
which is possible to return NULL which would cause a NULL pointer
dereference. Address this issue by checking return value of
fc_rport_create() and log error message on fc_rport_create() failed.
Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
---
drivers/scsi/libfc/fc_lport.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 9c02c9523c4d..904d66160785 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -241,6 +241,12 @@ static void fc_lport_ptp_setup(struct fc_lport *lport,
}
mutex_lock(&lport->disc.disc_mutex);
lport->ptp_rdata = fc_rport_create(lport, remote_fid);
+ if (!lport->ptp_rdata) {
+ printk(KERN_WARNING "libfc: Failed to setup lport 0x%x\n",
+ lport->port_id);
+ mutex_unlock(&lport->disc.disc_mutex);
+ return;
+ }
kref_get(&lport->ptp_rdata->kref);
lport->ptp_rdata->ids.port_name = remote_wwpn;
lport->ptp_rdata->ids.node_name = remote_wwnn;
--
2.32.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: libfc: Fix potential NULL pointer dereference in fc_lport_ptp_setup
2023-10-11 13:03 [PATCH] scsi: libfc: Fix potential NULL pointer dereference in fc_lport_ptp_setup Wenchao Hao
@ 2023-10-13 15:41 ` Simon Horman
2023-10-13 18:06 ` Martin K. Petersen
2023-10-17 1:11 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2023-10-13 15:41 UTC (permalink / raw)
To: Wenchao Hao
Cc: Hannes Reinecke, James E . J . Bottomley, Martin K . Petersen,
Richard Cochran, linux-scsi, linux-kernel, netdev, louhongxiang
On Wed, Oct 11, 2023 at 09:03:50PM +0800, Wenchao Hao wrote:
> fc_lport_ptp_setup() did not check the return value of fc_rport_create()
> which is possible to return NULL which would cause a NULL pointer
> dereference. Address this issue by checking return value of
> fc_rport_create() and log error message on fc_rport_create() failed.
>
> Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
Thanks,
I verified that fc_lport_ptp_setup can return NULL (if kzalloc fails).
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: libfc: Fix potential NULL pointer dereference in fc_lport_ptp_setup
2023-10-11 13:03 [PATCH] scsi: libfc: Fix potential NULL pointer dereference in fc_lport_ptp_setup Wenchao Hao
2023-10-13 15:41 ` Simon Horman
@ 2023-10-13 18:06 ` Martin K. Petersen
2023-10-17 1:11 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2023-10-13 18:06 UTC (permalink / raw)
To: Wenchao Hao
Cc: Hannes Reinecke, James E . J . Bottomley, Martin K . Petersen,
Richard Cochran, linux-scsi, linux-kernel, netdev, louhongxiang
Wenchao,
> fc_lport_ptp_setup() did not check the return value of
> fc_rport_create() which is possible to return NULL which would cause a
> NULL pointer dereference. Address this issue by checking return value
> of fc_rport_create() and log error message on fc_rport_create()
> failed.
Applied to 6.7/scsi-staging, thanks!
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: libfc: Fix potential NULL pointer dereference in fc_lport_ptp_setup
2023-10-11 13:03 [PATCH] scsi: libfc: Fix potential NULL pointer dereference in fc_lport_ptp_setup Wenchao Hao
2023-10-13 15:41 ` Simon Horman
2023-10-13 18:06 ` Martin K. Petersen
@ 2023-10-17 1:11 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2023-10-17 1:11 UTC (permalink / raw)
To: Hannes Reinecke, James E . J . Bottomley, Richard Cochran,
linux-scsi, Wenchao Hao
Cc: Martin K . Petersen, linux-kernel, netdev, louhongxiang
On Wed, 11 Oct 2023 21:03:50 +0800, Wenchao Hao wrote:
> fc_lport_ptp_setup() did not check the return value of fc_rport_create()
> which is possible to return NULL which would cause a NULL pointer
> dereference. Address this issue by checking return value of
> fc_rport_create() and log error message on fc_rport_create() failed.
>
>
Applied to 6.7/scsi-queue, thanks!
[1/1] scsi: libfc: Fix potential NULL pointer dereference in fc_lport_ptp_setup
https://git.kernel.org/mkp/scsi/c/4df105f0ce9f
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-10-17 1:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-11 13:03 [PATCH] scsi: libfc: Fix potential NULL pointer dereference in fc_lport_ptp_setup Wenchao Hao
2023-10-13 15:41 ` Simon Horman
2023-10-13 18:06 ` Martin K. Petersen
2023-10-17 1:11 ` Martin K. Petersen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).