[PATCH] fs: block_dev.c: fix WARNING in submit_bio_check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



duplicating the logic in blkdev_get_by_path to
blkdev_get_by_dev to avoid a user-triggerable WARN
trying to write to a read-only block device.

blkdev_get_by_path() looks at
((mode & FMODE_WRITE) && bdev_read_only(bdev)) to check for write permissions.

A user-triggerable WARN can be avoided by doing the same with bdev_get_by_dev.

Reported-by: syzbot+4c50ac32e5b10e4133e1@xxxxxxxxxxxxxxxxxxxxxxxxx
Signed-off-by: B K Karthik <karthik.bk2000@xxxxxxxx>
---
 fs/block_dev.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/block_dev.c b/fs/block_dev.c
index 64c4fe8181f2..472e3b046406 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1796,6 +1796,11 @@ struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder)
 	if (err)
 		return ERR_PTR(err);
 
+	if ((mode & FMODE_WRITE) && bdev_read_only(bdev)) {
+		blkdev_put(bdev, mode);
+		return ERR_PTR(-EACCES);
+	}
+
 	return bdev;
 }
 EXPORT_SYMBOL(blkdev_get_by_dev);
-- 
2.20.1

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux