Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: libfc: Fix potential NULL pointer dereference in fc_lport_ptp_setup()

fc_lport_ptp_setup() did not check the return value of fc_rport_create()
which can return NULL and 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>
Link: https://lore.kernel.org/r/20231011130350.819571-1-haowenchao2@huawei.com
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Wenchao Hao and committed by
Martin K. Petersen
4df105f0 f42706a8

+6
+6
drivers/scsi/libfc/fc_lport.c
··· 241 241 } 242 242 mutex_lock(&lport->disc.disc_mutex); 243 243 lport->ptp_rdata = fc_rport_create(lport, remote_fid); 244 + if (!lport->ptp_rdata) { 245 + printk(KERN_WARNING "libfc: Failed to setup lport 0x%x\n", 246 + lport->port_id); 247 + mutex_unlock(&lport->disc.disc_mutex); 248 + return; 249 + } 244 250 kref_get(&lport->ptp_rdata->kref); 245 251 lport->ptp_rdata->ids.port_name = remote_wwpn; 246 252 lport->ptp_rdata->ids.node_name = remote_wwnn;