Skip to contentSkip to conversation

block/compat_ioctl: fix range check in BLKGETSIZE

PATCH In review Khazhismel Kumykov 2 participants 3 messages Apr 6, 2018 – Aug 2, 2018 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block/compat_ioctl: fix range check in BLKGETSIZE

kernel ulong and compat_ulong_t may not be same width. Use type directly to eliminate mismatches.

This would result in truncation rather than EFBIG for 32bit mode for large disks.

---
 block/compat_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/compat_ioctl.c +1 -1
index 6ca015f92766..3a2c77f07da8 100644
@@ -388,7 +388,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
 		return 0;
 	case BLKGETSIZE:
 		size = i_size_read(bdev->bd_inode);
-		if ((size >> 9) > ~0UL)
+		if ((size >> 9) > ~((compat_ulong_t)0UL))
 			return -EFBIG;
 		return compat_put_ulong(arg, size >> 9);
 
Signature · 1 line
2.17.0.484.g0c8726318c-goog
#1 lore raw

Ping?

Quoted 27 lines · Khazhismel Kumykov

kernel ulong and compat_ulong_t may not be same width. Use type directly to eliminate mismatches.

This would result in truncation rather than EFBIG for 32bit mode for large disks.

---
 block/compat_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/compat_ioctl.c +1 -2
index 6ca015f92766..3a2c77f07da8 100644
@@ -388,7 +388,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
                return 0;
        case BLKGETSIZE:
                size = i_size_read(bdev->bd_inode);
-               if ((size >> 9) > ~0UL)
+               if ((size >> 9) > ~((compat_ulong_t)0UL))
                        return -EFBIG;
                return compat_put_ulong(arg, size >> 9);
 
--

2.17.0.484.g0c8726318c-goog

maintainer
#2 lore raw
In reply to Khazhismel Kumykov
Quoted 5 lines · Khazhismel Kumykov

kernel ulong and compat_ulong_t may not be same width. Use type directly to eliminate mismatches.

This would result in truncation rather than EFBIG for 32bit mode for large disks.

Sorry for not getting to this. Applied, thanks.

Signature · 1 line
Jens Axboe