Skip to contentSkip to conversation

megaraid_sas: fix physical disk handling

PATCH In review Christoph Hellwig 3 participants 5 messages Feb 6, 2006 – Feb 18, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 megaraid_sas: fix physical disk handling

Chandra_Nelogal noticed that megaraid_sas currently exports all physical disks normally to the disk layer, which is obviously quite bad.

The problems is that megaraid_sas is doing inquiry sniffing, and since 2.6.15 inquiry commands are sent down as one-element scatterlists on which the code in the driver doesn't work anymore. The right place to keep the scsi midlayer from attaching to a device is the slave_alloc method in the host template. To completely prevent attaching the method needs to return -ENXIO, but the patch below sets the no_uld_attach flag instead which prevents upper level drivers from attaching while still allowing scsi generic access to it, as in other raid HBA drivers.

drivers/scsi/megaraid/megaraid_sas.c +11 -14
Index: linux-2.6/drivers/scsi/megaraid/megaraid_sas.c
===================================================================
@@ -707,6 +707,16 @@
 	return 0;
 }
 
+static int megasas_slave_configure(struct scsi_device *sdev)
+{
+	/*
+	 * Don't export physical disk devices to the disk driver.
+	 */
+	if (sdev->channel < MEGASAS_MAX_PD_CHANNELS && sdev->type == TYPE_DISK)
+		sdev->no_uld_attach = 1;
+	return 0;
+}
+
 /**
  * megasas_wait_for_outstanding -	Wait for all outstanding cmds
  * @instance:				Adapter soft state
@@ -857,6 +867,7 @@
 	.module = THIS_MODULE,
 	.name = "LSI Logic SAS based MegaRAID driver",
 	.proc_name = "megaraid_sas",
+	.slave_configure = megasas_slave_configure,
 	.queuecommand = megasas_queue_command,
 	.eh_device_reset_handler = megasas_reset_device,
 	.eh_bus_reset_handler = megasas_reset_bus_host,
@@ -985,20 +996,6 @@
 			break;
 		}
 
-		/*
-		 * Don't export physical disk devices to mid-layer.
-		 */
-		if (!MEGASAS_IS_LOGICAL(cmd->scmd) &&
-		    (hdr->cmd_status == MFI_STAT_OK) &&
-		    (cmd->scmd->cmnd[0] == INQUIRY)) {
-
-			if (((*(u8 *) cmd->scmd->request_buffer) & 0x1F) ==
-			    TYPE_DISK) {
-				cmd->scmd->result = DID_BAD_TARGET << 16;
-				exception = 1;
-			}
-		}
-
 	case MFI_CMD_LD_READ:
 	case MFI_CMD_LD_WRITE:
 
#1 lore raw

Hello Christoph,

Thank you for the patch.

As you mentioned this patch allows scsi generic access to the
physical disks. I see this as potential data integrity issue if someone does a write operation on a disk that belongs to a Logical RAID volume. I would rather prevent all access to the disks using slave_alloc(). I will be sending a patch shortly for review that implements megasas_slave_alloc to block all direct access to the physical disks.

Regards,

Sumant

Quoted 65 lines · Christoph Hellwig

Chandra_Nelogal noticed that megaraid_sas currently exports all physical disks normally to the disk layer, which is obviously quite bad.

The problems is that megaraid_sas is doing inquiry sniffing, and since 2.6.15 inquiry commands are sent down as one-element scatterlists on which the code in the driver doesn't work anymore. The right place to keep the scsi midlayer from attaching to a device is the slave_alloc method in the host template. To completely prevent attaching the method needs to return -ENXIO, but the patch below sets the no_uld_attach flag instead which prevents upper level drivers from attaching while still allowing scsi generic access to it, as in other raid HBA drivers.

Index: linux-2.6/drivers/scsi/megaraid/megaraid_sas.c
===================================================================

drivers/scsi/megaraid/megaraid_sas.c +11 -14
@@ -707,6 +707,16 @@
 	return 0;
 }
 
+static int megasas_slave_configure(struct scsi_device *sdev)
+{
+	/*
+	 * Don't export physical disk devices to the disk driver.
+	 */
+	if (sdev->channel < MEGASAS_MAX_PD_CHANNELS && sdev->type == TYPE_DISK)
+		sdev->no_uld_attach = 1;
+	return 0;
+}
+
 /**
  * megasas_wait_for_outstanding -	Wait for all outstanding cmds
  * @instance:				Adapter soft state
@@ -857,6 +867,7 @@
 	.module = THIS_MODULE,
 	.name = "LSI Logic SAS based MegaRAID driver",
 	.proc_name = "megaraid_sas",
+	.slave_configure = megasas_slave_configure,
 	.queuecommand = megasas_queue_command,
 	.eh_device_reset_handler = megasas_reset_device,
 	.eh_bus_reset_handler = megasas_reset_bus_host,
@@ -985,20 +996,6 @@
 			break;
 		}
 
-		/*
-		 * Don't export physical disk devices to mid-layer.
-		 */
-		if (!MEGASAS_IS_LOGICAL(cmd->scmd) &&
-		    (hdr->cmd_status == MFI_STAT_OK) &&
-		    (cmd->scmd->cmnd[0] == INQUIRY)) {
-
-			if (((*(u8 *) cmd->scmd->request_buffer) & 0x1F) ==
-			    TYPE_DISK) {
-				cmd->scmd->result = DID_BAD_TARGET << 16;
-				exception = 1;
-			}
-		}
-
 	case MFI_CMD_LD_READ:
 	case MFI_CMD_LD_WRITE:
 
#2 lore raw
Quoted 10 lines · Sumant Patro

Hello Christoph,

Thank you for the patch.

As you mentioned this patch allows scsi generic access to the
physical disks. I see this as potential data integrity issue if someone does a write operation on a disk that belongs to a Logical RAID volume. I would rather prevent all access to the disks using slave_alloc(). I will be sending a patch shortly for review that implements megasas_slave_alloc to block all direct access to the physical disks.

Sumant,
Typically a non-root user would not have write (or read) permissions on a sg device node. A root user (or perhaps a user with CAP_SYS_RAWIO) could send a SCSI WRITE command to a physical disk, but that is no different from the current situation.

IMO The main reason to allow access to the physical "logical" units is for tools like smartmontools and access for commands like LOG SENSE and MODE SENSE (and perhaps the SELECT variants of those commands used carefully). Add INQUIRY to that list ...

With FC and SAS dual ported disks one could also think about taking a persistent reservation on one I_T nexus (e.g. the active port) and only allow access to the physical disk via the secondary port. That way the finer graded command filtering of PERSISTENT RESERVATION could be used to guard the integrity of the disk.

Doug Gilbert

#3 lore raw
In reply to Christoph Hellwig
Quoted 11 lines · Christoph Hellwig

Chandra_Nelogal noticed that megaraid_sas currently exports all physical disks normally to the disk layer, which is obviously quite bad.

The problems is that megaraid_sas is doing inquiry sniffing, and since 2.6.15 inquiry commands are sent down as one-element scatterlists on which the code in the driver doesn't work anymore. The right place to keep the scsi midlayer from attaching to a device is the slave_alloc method in the host template. To completely prevent attaching the method needs to return -ENXIO, but the patch below sets the no_uld_attach flag instead which prevents upper level drivers from attaching while still allowing scsi generic access to it, as in other raid HBA drivers.

I got feedback from LSI that they're very unhappy to allow generic access to the physical devices at this point because they haven't audited the firmware yet about what could happen if someone actually accesses the physical devices.

This patch hides the devices completely from the midlayer instead. It requires the patch to handle the slave_configure failure I posted earlier.

drivers/scsi/megaraid/megaraid_sas.c +15 -14
Index: linux-2.6/drivers/scsi/megaraid/megaraid_sas.c
===================================================================
@@ -707,6 +707,20 @@
 	return 0;
 }
 
+static int megasas_slave_configure(struct scsi_device *sdev)
+{
+	/*
+	 * Don't export physical disk devices to the disk driver.
+	 *
+	 * FIXME: Currently we don't export them to the midlayer at all.
+	 * 	  That will be fixed once LSI engineers have audited the
+	 * 	  firmware for possible issues.
+	 */
+	if (sdev->channel < MEGASAS_MAX_PD_CHANNELS && sdev->type == TYPE_DISK)
+		return -ENXIO;
+	return 0;
+}
+
 /**
  * megasas_wait_for_outstanding -	Wait for all outstanding cmds
  * @instance:				Adapter soft state
@@ -857,6 +871,7 @@
 	.module = THIS_MODULE,
 	.name = "LSI Logic SAS based MegaRAID driver",
 	.proc_name = "megaraid_sas",
+	.slave_configure = megasas_slave_configure,
 	.queuecommand = megasas_queue_command,
 	.eh_device_reset_handler = megasas_reset_device,
 	.eh_bus_reset_handler = megasas_reset_bus_host,
@@ -985,20 +1000,6 @@
 			break;
 		}
 
-		/*
-		 * Don't export physical disk devices to mid-layer.
-		 */
-		if (!MEGASAS_IS_LOGICAL(cmd->scmd) &&
-		    (hdr->cmd_status == MFI_STAT_OK) &&
-		    (cmd->scmd->cmnd[0] == INQUIRY)) {
-
-			if (((*(u8 *) cmd->scmd->request_buffer) & 0x1F) ==
-			    TYPE_DISK) {
-				cmd->scmd->result = DID_BAD_TARGET << 16;
-				exception = 1;
-			}
-		}
-
 	case MFI_CMD_LD_READ:
 	case MFI_CMD_LD_WRITE:
 
#4 lore raw
Quoted 13 lines · Christoph Hellwig
Quoted 11 lines · Christoph Hellwig

Chandra_Nelogal noticed that megaraid_sas currently exports all physical disks normally to the disk layer, which is obviously quite bad.

The problems is that megaraid_sas is doing inquiry sniffing, and since 2.6.15 inquiry commands are sent down as one-element scatterlists on which the code in the driver doesn't work anymore. The right place to keep the scsi midlayer from attaching to a device is the slave_alloc method in the host template. To completely prevent attaching the method needs to return -ENXIO, but the patch below sets the no_uld_attach flag instead which prevents upper level drivers from attaching while still allowing scsi generic access to it, as in other raid HBA drivers.

Quoted 9 lines

I got feedback from LSI that they're very unhappy to allow generic access to the physical devices at this point because they haven't audited the firmware yet about what could happen if someone actually accesses the physical devices.

This patch hides the devices completely from the midlayer instead. It requires the patch to handle the slave_configure failure I posted earlier.

Thank you.

--Sumant

Quoted 57 lines

Index: linux-2.6/drivers/scsi/megaraid/megaraid_sas.c
===================================================================

drivers/scsi/megaraid/megaraid_sas.c +15 -14
@@ -707,6 +707,20 @@
 	return 0;
 }
 
+static int megasas_slave_configure(struct scsi_device *sdev)
+{
+	/*
+	 * Don't export physical disk devices to the disk driver.
+	 *
+	 * FIXME: Currently we don't export them to the midlayer at all.
+	 * 	  That will be fixed once LSI engineers have audited the
+	 * 	  firmware for possible issues.
+	 */
+	if (sdev->channel < MEGASAS_MAX_PD_CHANNELS && sdev->type == TYPE_DISK)
+		return -ENXIO;
+	return 0;
+}
+
 /**
  * megasas_wait_for_outstanding -	Wait for all outstanding cmds
  * @instance:				Adapter soft state
@@ -857,6 +871,7 @@
 	.module = THIS_MODULE,
 	.name = "LSI Logic SAS based MegaRAID driver",
 	.proc_name = "megaraid_sas",
+	.slave_configure = megasas_slave_configure,
 	.queuecommand = megasas_queue_command,
 	.eh_device_reset_handler = megasas_reset_device,
 	.eh_bus_reset_handler = megasas_reset_bus_host,
@@ -985,20 +1000,6 @@
 			break;
 		}
 
-		/*
-		 * Don't export physical disk devices to mid-layer.
-		 */
-		if (!MEGASAS_IS_LOGICAL(cmd->scmd) &&
-		    (hdr->cmd_status == MFI_STAT_OK) &&
-		    (cmd->scmd->cmnd[0] == INQUIRY)) {
-
-			if (((*(u8 *) cmd->scmd->request_buffer) & 0x1F) ==
-			    TYPE_DISK) {
-				cmd->scmd->result = DID_BAD_TARGET << 16;
-				exception = 1;
-			}
-		}
-
 	case MFI_CMD_LD_READ:
 	case MFI_CMD_LD_WRITE: