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: [email protected]
Signed-off-by: B K Karthik <[email protected]>
---
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