Skip to contentSkip to conversation

nvme-multipath: avoid crash on invalid subsystem cntlid enumeration

PATCH New Hannes Reinecke 3 participants 7 messages Mar 29, 2019 – Apr 3, 2019 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme-multipath: avoid crash on invalid subsystem cntlid enumeration

The controller ID is supposed to be unique for each subsystem; however, if it _isn't_ we will crash when calling device_add_disk() for the namespaces.
While this surely is an error on the subsystem side we really shouldn't crash. So simply use the 'instance' number when generating the disk name to avoid this issue.

Signed-off-by Hannes Reinecke <hare at suse.com>
---
 drivers/nvme/host/multipath.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/multipath.c +1 -1
index f0716f6ce41f..2551264ef2b5 100644
@@ -31,7 +31,7 @@ void nvme_set_disk_name(char *disk_name, struct nvme_ns *ns,
 		sprintf(disk_name, "nvme%dn%d", ctrl->instance, ns->head->instance);
 	} else if (ns->head->disk) {
 		sprintf(disk_name, "nvme%dc%dn%d", ctrl->subsys->instance,
-				ctrl->cntlid, ns->head->instance);
+				ctrl->instance, ns->head->instance);
 		*flags = GENHD_FL_HIDDEN;
 	} else {
 		sprintf(disk_name, "nvme%dn%d", ctrl->subsys->instance,
Signature · 1 line
2.16.4
#1 lore raw

PATCH 1/1 nvme-multipath: avoid crash on invalid subsystem cntlid enumeration

Quoted 6 lines · Hannes Reinecke

The controller ID is supposed to be unique for each subsystem; however, if it _isn't_ we will crash when calling device_add_disk() for the namespaces.
While this surely is an error on the subsystem side we really shouldn't crash. So simply use the 'instance' number when generating the disk name to avoid this issue.

I agree that we should not crash in that, but I'd rather print an error message and reject using that controller with the duplicate controller id than hacking around the issue.

#2 lore raw

PATCH 1/1 nvme-multipath: avoid crash on invalid subsystem cntlid enumeration

Quoted 8 lines · Christoph Hellwig
Quoted 6 lines · Hannes Reinecke

The controller ID is supposed to be unique for each subsystem; however, if it _isn't_ we will crash when calling device_add_disk() for the namespaces.
While this surely is an error on the subsystem side we really shouldn't crash. So simply use the 'instance' number when generating the disk name to avoid this issue.

Quoted 4 lines

I agree that we should not crash in that, but I'd rather print an error message and reject using that controller with the duplicate controller id than hacking around the issue.

As it so happens, I have a patch for that, too, but thought this one an easier solution :-)

Will be sending that patch, then.

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare at suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG N?rnberg)
maintainer
#3 lore raw

PATCH 1/1 nvme-multipath: avoid crash on invalid subsystem cntlid enumeration

Quoted 9 lines · Hannes Reinecke
Quoted 8 lines · Christoph Hellwig
Quoted 6 lines · Hannes Reinecke

The controller ID is supposed to be unique for each subsystem; however, if it _isn't_ we will crash when calling device_add_disk() for the namespaces.
While this surely is an error on the subsystem side we really shouldn't crash. So simply use the 'instance' number when generating the disk name to avoid this issue.

Quoted 8 lines
Quoted 4 lines

I agree that we should not crash in that, but I'd rather print an error message and reject using that controller with the duplicate controller id than hacking around the issue.

As it so happens, I have a patch for that, too, but thought this one an easier solution :-)

Will be sending that patch, then.

We might want to use this patch anyway. It is possible some process reference count is preventing the final release when we want to remove a controller, and a subsequent discover, even if the cntlid is unqiue, would create a duplicate disk name.

#4 lore raw

PATCH 1/1 nvme-multipath: avoid crash on invalid subsystem cntlid enumeration

Quoted 17 lines · Keith Busch
Quoted 16 lines · Hannes Reinecke
Quoted 8 lines · Christoph Hellwig
Quoted 6 lines · Hannes Reinecke

The controller ID is supposed to be unique for each subsystem; however, if it _isn't_ we will crash when calling device_add_disk() for the namespaces.
While this surely is an error on the subsystem side we really shouldn't crash. So simply use the 'instance' number when generating the disk name to avoid this issue.

Quoted 4 lines

I agree that we should not crash in that, but I'd rather print an error message and reject using that controller with the duplicate controller id than hacking around the issue.

As it so happens, I have a patch for that, too, but thought this one an easier solution :-)

Quoted 7 lines
Quoted 1 line

Will be sending that patch, then.

We might want to use this patch anyway. It is possible some process reference count is preventing the final release when we want to remove a controller, and a subsequent discover, even if the cntlid is unqiue, would create a duplicate disk name.

I don't mind which patch is taken.
But crashing on misbehaving targets is never a good idea.

Do I need to send the other patch?

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke            Teamlead Storage & Networking
hare at suse.de                              +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG N?rnberg)
maintainer
#5 lore raw

PATCH 1/1 nvme-multipath: avoid crash on invalid subsystem cntlid enumeration

Quoted 8 lines · Hannes Reinecke
Quoted 5 lines · Keith Busch

We might want to use this patch anyway. It is possible some process reference count is preventing the final release when we want to remove a controller, and a subsequent discover, even if the cntlid is unqiue, would create a duplicate disk name.

I don't mind which patch is taken.
But crashing on misbehaving targets is never a good idea.

I 100% agree. :)

Quoted 1 line

Do I need to send the other patch?

Can we do both? I like the warning when an invalid subsystem is detected, but your original patch fixes the unique gendisk name, so I'd vote to keep that good code, but justify it with a slightly different changelog. Something along the following:

A process holding an open reference to a removed disk prevents it from completing deletion, so its name continues to exist. A subsequent gendisk creation may have the same cntlid which risks collision when using that for the name. Use the unique ctrl->instance instead.

#6 lore raw

PATCH 1/1 nvme-multipath: avoid crash on invalid subsystem cntlid enumeration

Quoted 10 lines · Keith Busch
Quoted 8 lines · Hannes Reinecke
Quoted 5 lines · Keith Busch

We might want to use this patch anyway. It is possible some process reference count is preventing the final release when we want to remove a controller, and a subsequent discover, even if the cntlid is unqiue, would create a duplicate disk name.

I don't mind which patch is taken.
But crashing on misbehaving targets is never a good idea.

Quoted 8 lines

I 100% agree. :)

Quoted 1 line

Do I need to send the other patch?

Can we do both? I like the warning when an invalid subsystem is detected, but your original patch fixes the unique gendisk name, so I'd vote to keep that good code, but justify it with a slightly different changelog. Something along the following:

Yes, let's do both. Hannes, please resend a series with this patch with the updated changelog and the duplicate cntlid check one.