Skip to contentSkip to conversation

scsi: libfc: Fix potential NULL pointer dereference

PATCH In review YueHaibing 3 participants 5 messages Jan 30, 2019 – Mar 14, 2019

Subsystems (2)
lore
Share & tools
lore

YueHaibing

author
#0 lore raw

PATCH 1/1 scsi: libfc: Fix potential NULL pointer dereference

There is a potential NULL pointer dereference in case fc_rport_create() fails and returns NULL.

Fixes 2580064b5ec6 ("scsi: libfc: Replace ->rport_create callback with function call")
---
 drivers/scsi/libfc/fc_lport.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/scsi/libfc/fc_lport.c +4 -0
index ff943f4..e2a3551 100644
@@ -250,6 +250,10 @@ 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) {
+		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;
Signature · 1 line
2.7.0
author
#1 lore raw

Friendly ping:

Who can review or take this, please?

Thanks

Quoted 25 lines · YueHaibing

There is a potential NULL pointer dereference in case fc_rport_create() fails and returns NULL.

Fixes 2580064b5ec6 ("scsi: libfc: Replace ->rport_create callback with function call")
---
 drivers/scsi/libfc/fc_lport.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/scsi/libfc/fc_lport.c +4 -0
index ff943f4..e2a3551 100644
@@ -250,6 +250,10 @@ 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) {
+		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;
maintainer
#2 lore raw
Quoted 17 lines · YueHaibing

Friendly ping:

Who can review or take this, please?

Thanks

Quoted 9 lines · YueHaibing

There is a potential NULL pointer dereference in case fc_rport_create() fails and returns NULL.

Fixes 2580064b5ec6 ("scsi: libfc: Replace ->rport_create callback with function call")
---
  drivers/scsi/libfc/fc_lport.c | 4 ++++
  1 file changed, 4 insertions(+)
Quoted 17 lines
Quoted 6 lines
drivers/scsi/libfc/fc_lport.c +0 -0
index ff943f4..e2a3551 100644

drivers/scsi/libfc/fc_lport.c static void fc_lport_ptp_setup(struct fc_lport *lport, · line 259

Quoted 10 lines
drivers/scsi/libfc/fc_lport.c +4 -0
@@ -250,6 +250,10 @@ 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) {
+		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;

I don't think this is correct.
While it's true that fc_rport_create() might fail, fc_lport_ptp_setup() will still assumed to have worked by the caller. So we should rather return an error code here from fc_lport_ptp_setup() and ensure it's handled properly in the caller, too.

Cheers,

Hannes

maintainer Reviewed-by
#3 lore raw
In reply to YueHaibing
Quoted 17 lines · YueHaibing

Friendly ping:

Who can review or take this, please?

Thanks

Quoted 9 lines · YueHaibing

There is a potential NULL pointer dereference in case fc_rport_create() fails and returns NULL.

Fixes 2580064b5ec6 ("scsi: libfc: Replace ->rport_create callback with function call")
---
  drivers/scsi/libfc/fc_lport.c | 4 ++++
  1 file changed, 4 insertions(+)
Quoted 17 lines
Quoted 6 lines
drivers/scsi/libfc/fc_lport.c +0 -0
index ff943f4..e2a3551 100644

drivers/scsi/libfc/fc_lport.c static void fc_lport_ptp_setup(struct fc_lport *lport, · line 259

Quoted 10 lines
drivers/scsi/libfc/fc_lport.c +4 -0
@@ -250,6 +250,10 @@ 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) {
+		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;

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
#4 lore raw

Hi Hannes,

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

There is a potential NULL pointer dereference in case fc_rport_create() fails and returns NULL.

drivers/scsi/libfc/fc_lport.c +2 -0
index ff943f4..e2a3551 100644
@@ -250,6 +250,10 @@ 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) {
+		mutex_unlock(&lport->disc.disc_mutex);
Quoted 8 lines
Quoted 6 lines

drivers/scsi/libfc/fc_lport.c static void fc_lport_ptp_setup(struct fc_lport *lport, · line 259

Quoted 6 lines
drivers/scsi/libfc/fc_lport.c +2 -0
+		return;
+	}
  	kref_get(&lport->ptp_rdata->kref);
  	lport->ptp_rdata->ids.port_name = remote_wwpn;
  	lport->ptp_rdata->ids.node_name = remote_wwnn;

A bit confused. You had originally replied that the patch was not correct so I closed it in patchwork. And now there's a Reviewed-by:
without any explanation as to why you have changed your mind.

Please clarify, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering