Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] fs: block_dev.c: fix WARNING in submit_bio_check
@ 2020-07-15 12:50 B K Karthik
  0 siblings, 0 replies; only message in thread
From: B K Karthik @ 2020-07-15 12:50 UTC (permalink / raw)
  To: Alexander Viro, linux-fsdevel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 997 bytes --]

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@syzkaller.appspotmail.com
Signed-off-by: B K Karthik <karthik.bk2000@live.com>
---
 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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-07-15 12:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-15 12:50 [PATCH] fs: block_dev.c: fix WARNING in submit_bio_check B K Karthik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).