From 876414065bd486bff54d11dea81031848062d7f5 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Thu, 21 Jun 2018 10:23:52 -0700 Subject: [PATCH] scoutfs: warn if we try IO outside the device We've had bugs in allocators that return success and crazy block numbers. The bad block numbers eventually make their way down to the context-free kernel warning that IO was attempted outside the device. This at least gives us a stack trace to help find where it's coming from. Signed-off-by: Zach Brown --- kmod/src/bio.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kmod/src/bio.c b/kmod/src/bio.c index b8e94b46..f47ed7b2 100644 --- a/kmod/src/bio.c +++ b/kmod/src/bio.c @@ -69,6 +69,7 @@ void scoutfs_bio_submit(struct super_block *sb, int rw, struct page **pages, { unsigned int nr_pages = DIV_ROUND_UP(nr_blocks, SCOUTFS_BLOCKS_PER_PAGE); + struct scoutfs_super_block *super = &SCOUTFS_SB(sb)->super; struct bio_end_io_args *args; struct blk_plug plug; unsigned int bytes; @@ -77,6 +78,12 @@ void scoutfs_bio_submit(struct super_block *sb, int rw, struct page **pages, int ret = 0; int i; + if (super->total_blocks && + WARN_ON_ONCE(blkno >= le64_to_cpu(super->total_blocks))) { + end_io(sb, data, -EIO); + return; + } + args = kmalloc(sizeof(struct bio_end_io_args), GFP_NOFS); if (!args) { end_io(sb, data, -ENOMEM);