Skip to contentSkip to conversation

s390: add missing validation for dasd discipline specific ioctls

PATCH In review Heiko Carstens 2 participants 2 messages Feb 8, 2006

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

PATCH 5/10 s390: add missing validation for dasd discipline specific ioctls

From: Horst Hummel <[email protected]>

Because of missing discipline validition dasd ioctls calls may not return when called on a device handled by a different discipline. (e.g calling ECKD specific BIODASDGATTR on an FBA device). This addresses one of the issues Christoph has with the dasd driver.

---

 drivers/s390/block/dasd.c      |    8 ++++-
 drivers/s390/block/dasd_eckd.c |   59 ++++++++++++++++++++++++++++-------------
 drivers/s390/block/dasd_eer.c  |   39 +++++++++++++++++++++------
 3 files changed, 78 insertions(+), 28 deletions(-)
drivers/s390/block/dasd.c +6 -2
diff -urpN linux-2.6/drivers/s390/block/dasd.c linux-2.6-patched/drivers/s390/block/dasd.c
@@ -670,8 +670,10 @@ dasd_term_IO(struct dasd_ccw_req * cqr)
 
 	/* Check the cqr */
 	rc = dasd_check_cqr(cqr);
-	if (rc)
+	if (rc) {
+		cqr->status = DASD_CQR_FAILED;
 		return rc;
+	}
 	retries = 0;
 	device = (struct dasd_device *) cqr->device;
 	while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
@@ -724,8 +726,10 @@ dasd_start_IO(struct dasd_ccw_req * cqr)
 
 	/* Check the cqr */
 	rc = dasd_check_cqr(cqr);
-	if (rc)
+	if (rc) {
+		cqr->status = DASD_CQR_FAILED;
 		return rc;
+	}
 	device = (struct dasd_device *) cqr->device;
 	if (cqr->retries < 0) {
 		DEV_MESSAGE(KERN_DEBUG, device,
drivers/s390/block/dasd_eckd.c +41 -18

101 lines not on this page · raw message

drivers/s390/block/dasd_eer.c +31 -8
diff -urpN linux-2.6/drivers/s390/block/dasd_eer.c linux-2.6-patched/drivers/s390/block/dasd_eer.c
@@ -109,6 +109,28 @@ static spinlock_t bufferlock = SPIN_LOCK
 DECLARE_WAIT_QUEUE_HEAD(dasd_eer_read_wait_queue);
 
 /*
+ * Check if called ioctl is valid on this device type.
+ * Returns device if anything is fine, ERR_PTR otherwise.
+ */
+static inline struct dasd_device *
+dasd_eer_validate_ioctl(struct block_device *bdev, int no)
+{
+	struct dasd_device *device;
+
+	device = bdev->bd_disk->private_data;
+	if (device == NULL)
+		return ERR_PTR(-ENODEV);
+
+	if (strncmp((char *)&device->discipline->name, "ECKD", 4)) {
+		DEV_MESSAGE(KERN_WARNING, device,
+			    "ioctl (%x) not supported for %.4s device.",
+			    no, (char *)&device->discipline->name);
+		return ERR_PTR(-EOPNOTSUPP);
+	}
+	return device;
+}
+
+/*
  * How many free bytes are available on the buffer.
  * needs to be called with bufferlock held
  */
@@ -523,8 +545,7 @@ static int
 dasd_eer_enable_on_device(struct dasd_device *device)
 {
 	void *eer;
-	if (!device)
-		return -ENODEV;
+
 	if (device->eer)
 		return 0;
 	if (!try_module_get(THIS_MODULE)) {
@@ -575,9 +596,10 @@ dasd_ioctl_set_eer(struct block_device *
 		return -EINVAL;
 	if (get_user(intval, (int __user *) args))
 		return -EFAULT;
-	device =  bdev->bd_disk->private_data;
-	if (device == NULL)
-		return -ENODEV;
+
+	device = dasd_eer_validate_ioctl(bdev, no);
+	if (IS_ERR(device))
+		return PTR_ERR(device);
 
 	intval = (intval != 0);
 	DEV_MESSAGE (KERN_DEBUG, device,
@@ -597,9 +619,10 @@ dasd_ioctl_get_eer(struct block_device *
 {
 	struct dasd_device *device;
 
-	device =  bdev->bd_disk->private_data;
-	if (device == NULL)
-		return -ENODEV;
+	device = dasd_eer_validate_ioctl(bdev, no);
+	if (IS_ERR(device))
+		return PTR_ERR(device);
+
 	return put_user((device->eer != NULL), (int __user *) args);
 }
 
#1 lore raw
Quoted 6 lines · Heiko Carstens

From: Horst Hummel <[email protected]>

Because of missing discipline validition dasd ioctls calls may not return when called on a device handled by a different discipline. (e.g calling ECKD specific BIODASDGATTR on an FBA device). This addresses one of the issues Christoph has with the dasd driver.

Nack. the right way to do this is to have per-discipline ioctl methods, even if we can't remove the dasd_ioctl_register interface yet due to other disagreements. Just resurect those parts of my patch.