Thread (9 messages) 9 messages, 8 authors, 2025-07-28

Re: [PATCH] [v2] block: fix FS_IOC_GETLBMD_CAP parsing in blkdev_common_ioctl()

From: Klara Modin <hidden>
Date: 2025-07-24 10:16:43
Also in: lkml

On 2025-07-18 07:56:49 +0200, Arnd Bergmann wrote:
On Fri, Jul 18, 2025, at 01:37, Klara Modin wrote:
  
quoted
quoted
diff --git a/block/ioctl.c b/block/ioctl.c
index 9ad403733e19..af2e22e5533c 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -566,9 +566,11 @@ static int blkdev_common_ioctl(struct block_device *bdev, blk_mode_t mode,
 			       void __user *argp)
 {
 	unsigned int max_sectors;
+	int ret;
 
-	if (_IOC_NR(cmd) == _IOC_NR(FS_IOC_GETLBMD_CAP))
-		return blk_get_meta_cap(bdev, cmd, argp);
quoted
+	ret = blk_get_meta_cap(bdev, cmd, argp);
+	if (ret != -ENOIOCTLCMD)
+		return ret;
This check seems to be incomplete. In the case when BLK_DEV_INTEGRITY is
disabled the ioctl can never complete as blk_get_meta_cap will then
always return -EOPNOTSUPP. Or should the !BLK_DEV_INTEGRITY stub be
changed to return -ENOIOCTLCMD instead?
Ah, I did miss the stub.
quoted
It makes e.g. cryptsetup fail in my initramfs. Adding -EOPNOTSUPP to the
check fixes it for me:
diff --git a/block/ioctl.c b/block/ioctl.c
index af2e22e5533c..7d5361fd1b7d 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -569,7 +569,7 @@ static int blkdev_common_ioctl(struct block_device 
*bdev, blk_mode_t mode,
 	int ret;

 	ret = blk_get_meta_cap(bdev, cmd, argp);
-	if (ret != -ENOIOCTLCMD)
+	if (ret != -EOPNOTSUPP && ret != -ENOIOCTLCMD)
 		return ret;

 	switch (cmd) {
I think returning -ENOIOCTLCMD from the stub makes more sense,
but I don't know what the motivation for the -EOPNOTSUPP was.

     Arnd
Should I send a patch changing the stub? At least from reading
Documentation/driver-api/ioctl.rst it seems clear that only -ENOIOCTLCMD
or -ENOTTY is correct when the command number is unknown.

I didn't find any particular reason in 9eb22f7fedfc ("fs: add ioctl to
query metadata and protection info capabilities") for the -EOPNOTSUPP
return.

Regards,
Klara Modin
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help