Skip to contentSkip to conversation

BLKBSZSET ioctl: fixes possibly silent blocksize change failure

PATCH New Lou Langholtz 1 participant 1 message Jul 13, 2003 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 BLKBSZSET ioctl: fixes possibly silent blocksize change failure

Here's a small patch that fixes a failure to return -EINVAL to user when calling the BLKBSZSET ioctl and the requested new blocksize passed in is smaller than bdev_hardsect_size(bdev). This patch applies against 2.5.75 through 2.5.75-bk2 (I have not tried applying the patch against any other releases). A quick glance at the 2.4.20 code shows the same bug to exist their too (as I suspect is in later 2.4 release also). A side effect of this patch is that checking is re-ordered between checking if busy and whether the new blocksize is valid. Programs expecting this ioctl to validate the new size before checking if busy would need to be updated to handle the new checking order.

drivers/block/ioctl.c +2 -4
diff -urN linux-2.5.75/drivers/block/ioctl.c linux-2.5.75-patched/drivers/block/ioctl.c
@@ -166,13 +166,11 @@
 			return -EINVAL;
 		if (get_user(n, (int *) arg))
 			return -EFAULT;
-		if (n > PAGE_SIZE || n < 512 || (n & (n - 1)))
-			return -EINVAL;
 		if (bd_claim(bdev, &holder) < 0)
 			return -EBUSY;
-		set_blocksize(bdev, n);
+		ret = set_blocksize(bdev, n);
 		bd_release(bdev);
-		return 0;
+		return ret;
 	case BLKPG:
 		return blkpg_ioctl(bdev, (struct blkpg_ioctl_arg *) arg);
 	case BLKRRPART: