]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
scsi: device_handler: Return error pointer in scsi_dh_attached_handler_name()
authorBenjamin Marzinski <bmarzins@redhat.com>
Sat, 6 Dec 2025 01:00:15 +0000 (20:00 -0500)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 9 Dec 2025 03:04:38 +0000 (22:04 -0500)
If scsi_dh_attached_handler_name() fails to allocate the handler name,
dm-multipath (its only caller) assumes there is no attached device
handler, and sets the device up incorrectly. Return an error pointer
instead, so multipath can distinguish between failure, success where
there is no attached device handler, or when the path device is not a
SCSI device at all.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
Link: https://patch.msgid.link/20251206010015.1595225-1-bmarzins@redhat.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/md/dm-mpath.c
drivers/scsi/scsi_dh.c

index aaf4a0a4b0ebb66fb5f2427d1f504c9a1b11502e..1f3989ad2f7de1df980df332152ce17db1a63494 100644 (file)
@@ -962,6 +962,19 @@ static struct pgpath *parse_path(struct dm_arg_set *as, struct path_selector *ps
 
        q = bdev_get_queue(p->path.dev->bdev);
        attached_handler_name = scsi_dh_attached_handler_name(q, GFP_KERNEL);
+       if (IS_ERR(attached_handler_name)) {
+               if (PTR_ERR(attached_handler_name) == -ENODEV) {
+                       if (m->hw_handler_name) {
+                               DMERR("hardware handlers are only allowed for SCSI devices");
+                               kfree(m->hw_handler_name);
+                               m->hw_handler_name = NULL;
+                       }
+                       attached_handler_name = NULL;
+               } else {
+                       r = PTR_ERR(attached_handler_name);
+                       goto bad;
+               }
+       }
        if (attached_handler_name || m->hw_handler_name) {
                INIT_DELAYED_WORK(&p->activate_path, activate_path_work);
                r = setup_scsi_dh(p->path.dev->bdev, m, &attached_handler_name, &ti->error);
index 7b56e00c7df6b02caa4dd2eb99bfc40554b4a403..b9d805317814947466a4f72d60d58557093be24b 100644 (file)
@@ -353,7 +353,8 @@ EXPORT_SYMBOL_GPL(scsi_dh_attach);
  *      that may have a device handler attached
  * @gfp - the GFP mask used in the kmalloc() call when allocating memory
  *
- * Returns name of attached handler, NULL if no handler is attached.
+ * Returns name of attached handler, NULL if no handler is attached, or
+ * and error pointer if an error occurred.
  * Caller must take care to free the returned string.
  */
 const char *scsi_dh_attached_handler_name(struct request_queue *q, gfp_t gfp)
@@ -363,10 +364,11 @@ const char *scsi_dh_attached_handler_name(struct request_queue *q, gfp_t gfp)
 
        sdev = scsi_device_from_queue(q);
        if (!sdev)
-               return NULL;
+               return ERR_PTR(-ENODEV);
 
        if (sdev->handler)
-               handler_name = kstrdup(sdev->handler->name, gfp);
+               handler_name = kstrdup(sdev->handler->name, gfp) ? :
+                              ERR_PTR(-ENOMEM);
        put_device(&sdev->sdev_gendev);
        return handler_name;
 }