Skip to contentSkip to conversation

dm: don't allow ioctls to targets that don't map to whole devices

PATCH Superseded Christoph Hellwig 3 participants 4 messages Feb 3, 2017

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm: don't allow ioctls to targets that don't map to whole devices

.. at least for unprivilegued users. Before we called into the SCSI ioctl code to allow excemptions for a few SCSI passthrough ioctls, but this is pretty unsafe and except for this call dm knows nothing about SCSI ioctls. As SCSI the SCSI ioctl code is made optionally now we really don't want to drag it in for DM, and the exception is not very useful anyway.

Note: this should go into the block tree, as that's where scsi_verify_blk_ioctl becomes optional.

---
 drivers/md/dm.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/md/dm.c +8 -5
index 9e958bc94fed..adc9dcfd5e9c 100644
@@ -465,13 +465,16 @@ static int dm_blk_ioctl(struct block_device *bdev, fmode_t mode,
 
 	if (r > 0) {
 		/*
-		 * Target determined this ioctl is being issued against
-		 * a logical partition of the parent bdev; so extra
-		 * validation is needed.
+		 * Target determined this ioctl is being issued against a
+		 * subset of the parent bdev; require extra privilegues.
 		 */
-		r = scsi_verify_blk_ioctl(NULL, cmd);
-		if (r)
+		if (!capable(CAP_SYS_RAWIO)) {
+			printk_ratelimited(KERN_WARNING
+				"%s: sending ioctl %x to DM device!\n",
+				current->comm, cmd);
+			r = -ENOIOCTLCMD;
 			goto out;
+		}
 	}
 
 	r =  __blkdev_driver_ioctl(bdev, mode, cmd, arg);
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Christoph Hellwig

.. at least for unprivilegued users. Before we called into the SCSI ioctl code to allow excemptions for a few SCSI passthrough ioctls, but this is pretty unsafe and except for this call dm knows nothing about SCSI ioctls. As SCSI the SCSI ioctl code is made optionally

^~ duped SCSI or should it
read "as in SCSI the SCSI ioctl code [...]"

Quoted 9 lines

now we really don't want to drag it in for DM, and the exception is not very useful anyway.

Note: this should go into the block tree, as that's where scsi_verify_blk_ioctl becomes optional.

---

Rest looks OK to me,

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
#2 lore raw
Quoted 7 lines · Johannes Thumshirn
Quoted 4 lines · Christoph Hellwig

.. at least for unprivilegued users. Before we called into the SCSI ioctl code to allow excemptions for a few SCSI passthrough ioctls, but this is pretty unsafe and except for this call dm knows nothing about SCSI ioctls. As SCSI the SCSI ioctl code is made optionally

^~ duped SCSI or should it
read "as in SCSI the SCSI ioctl code [...]"

Yeah, thanks.

Acked-by on v1 1/1
#3 lore raw
In reply to Christoph Hellwig
Quoted 45 lines · Christoph Hellwig

.. at least for unprivilegued users. Before we called into the SCSI ioctl code to allow excemptions for a few SCSI passthrough ioctls, but this is pretty unsafe and except for this call dm knows nothing about SCSI ioctls. As SCSI the SCSI ioctl code is made optionally now we really don't want to drag it in for DM, and the exception is not very useful anyway.

Note: this should go into the block tree, as that's where scsi_verify_blk_ioctl becomes optional.

---
 drivers/md/dm.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/md/dm.c +8 -5
index 9e958bc94fed..adc9dcfd5e9c 100644
@@ -465,13 +465,16 @@ static int dm_blk_ioctl(struct block_device *bdev, fmode_t mode,
 
 	if (r > 0) {
 		/*
-		 * Target determined this ioctl is being issued against
-		 * a logical partition of the parent bdev; so extra
-		 * validation is needed.
+		 * Target determined this ioctl is being issued against a
+		 * subset of the parent bdev; require extra privilegues.
 		 */
-		r = scsi_verify_blk_ioctl(NULL, cmd);
-		if (r)
+		if (!capable(CAP_SYS_RAWIO)) {
+			printk_ratelimited(KERN_WARNING
+				"%s: sending ioctl %x to DM device!\n",
+				current->comm, cmd);
+			r = -ENOIOCTLCMD;
 			goto out;
+		}
 	}
 
 	r =  __blkdev_driver_ioctl(bdev, mode, cmd, arg);
Signature · 1 line
2.11.0

Would prefer to see the use of DMERR_LIMIT() or DMWARN_LIMIT() as those wrappers provide error message consistency across DM core and DM targets. Also, would make sense to say: "sending ioctl %x to DM device without required privilege (CAP_SYS_RAWIO)."

(you have a couple s/privilegue/privilege typos)

And this patch will need Paolo's ack before being staged.

Otherwise, look good: