Skip to contentSkip to conversation

NVMe: Remove duplicate compat SG_IO code

PATCH New Keith Busch 2 participants 3 messages Aug 27, 2014

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

PATCH 1/2 NVMe: Remove duplicate compat SG_IO code

We can return -ENOIOCTLCMD and the ioctl will be handled by fs/compat_ioctl.c instead. This removes a lot of duplicate code in the nvme driver.

Signed-off-by Keith Busch <keith.busch at intel.com>
---
 drivers/block/nvme-core.c |    4 +-
 drivers/block/nvme-scsi.c |  146 ---------------------------------------------
 2 files changed, 1 insertion(+), 149 deletions(-)
drivers/block/nvme-core.c +1 -3
index 28aec2d..959149b 100644
@@ -1797,11 +1797,9 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
 static int nvme_compat_ioctl(struct block_device *bdev, fmode_t mode,
 					unsigned int cmd, unsigned long arg)
 {
-	struct nvme_ns *ns = bdev->bd_disk->private_data;
-
 	switch (cmd) {
 	case SG_IO:
-		return nvme_sg_io32(ns, arg);
+		return -ENOIOCTLCMD;
 	}
 	return nvme_ioctl(bdev, mode, cmd, arg);
 }
drivers/block/nvme-scsi.c +0 -146

152 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 2/2 NVMe: Fix SG_IO status values

We've only been setting the sg_io_hdr status values on SCSI commands that require an nvme command to complete the translation. The fields in the struct are output parameters, so we have to set them, otherwise user space will see whatever was in memory from before. In the case of compat SG_IO, this would reveal kernel memory. This fixes the issue by initializing the sg_io_hdr with successful status.

Signed-off-by Keith Busch <keith.busch at intel.com>
---
 drivers/block/nvme-scsi.c |    8 ++++++++
 1 file changed, 8 insertions(+)
drivers/block/nvme-scsi.c +8 -0
index dabafa6a..046ae33 100644
@@ -2915,6 +2915,14 @@ static int nvme_scsi_translate(struct nvme_ns *ns, struct sg_io_hdr *hdr)
 	if (copy_from_user(cmd, hdr->cmdp, hdr->cmd_len))
 		return -EFAULT;
 
+	/*
+	 * Prime the hdr with good status for scsi commands that don't require
+	 * an nvme command for translation.
+	 */
+	retcode = nvme_trans_status_code(hdr, NVME_SC_SUCCESS);
+	if (retcode)
+		return retcode;
+
 	opcode = cmd[0];
 
 	switch (opcode) {
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/2 NVMe: Fix SG_IO status values

Quoted 7 lines · Keith Busch

We've only been setting the sg_io_hdr status values on SCSI commands that require an nvme command to complete the translation. The fields in the struct are output parameters, so we have to set them, otherwise user space will see whatever was in memory from before. In the case of compat SG_IO, this would reveal kernel memory. This fixes the issue by initializing the sg_io_hdr with successful status.

Quoted 5 lines
Signed-off-by Keith Busch <keith.busch at intel.com>
---
 drivers/block/nvme-scsi.c |    8 ++++++++
 1 file changed, 8 insertions(+)
Acked-by Vishal Verma <vishal.l.verma at linux.intel.com>