Skip to content

Commit 9f0f659

Browse files
Darrick J. Wonggregkh
authored andcommitted
iomap: error out on file IO when there is no inline_data buffer
[ Upstream commit 6a96fb653b6481ec73e9627ade216b299e4de9ea ] Return IO errors if an ->iomap_begin implementation returns an IOMAP_INLINE buffer but forgets to set the inline_data pointer. Filesystems should never do this, but we could help fs developers (me) fix their bugs by handling this more gracefully than crashing the kernel. Signed-off-by: Darrick J. Wong <[email protected]> Link: https://lore.kernel.org/175803480324.966383.7414345025943296442.stgit@frogsfrogsfrogs Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Christian Brauner <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 8167718 commit 9f0f659

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

fs/iomap/buffered-io.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ static int iomap_read_inline_data(const struct iomap_iter *iter,
304304
size_t size = i_size_read(iter->inode) - iomap->offset;
305305
size_t offset = offset_in_folio(folio, iomap->offset);
306306

307+
if (WARN_ON_ONCE(!iomap->inline_data))
308+
return -EIO;
309+
307310
if (folio_test_uptodate(folio))
308311
return 0;
309312

@@ -894,7 +897,7 @@ static bool __iomap_write_end(struct inode *inode, loff_t pos, size_t len,
894897
return true;
895898
}
896899

897-
static void iomap_write_end_inline(const struct iomap_iter *iter,
900+
static bool iomap_write_end_inline(const struct iomap_iter *iter,
898901
struct folio *folio, loff_t pos, size_t copied)
899902
{
900903
const struct iomap *iomap = &iter->iomap;
@@ -903,12 +906,16 @@ static void iomap_write_end_inline(const struct iomap_iter *iter,
903906
WARN_ON_ONCE(!folio_test_uptodate(folio));
904907
BUG_ON(!iomap_inline_data_valid(iomap));
905908

909+
if (WARN_ON_ONCE(!iomap->inline_data))
910+
return false;
911+
906912
flush_dcache_folio(folio);
907913
addr = kmap_local_folio(folio, pos);
908914
memcpy(iomap_inline_data(iomap, pos), addr, copied);
909915
kunmap_local(addr);
910916

911917
mark_inode_dirty(iter->inode);
918+
return true;
912919
}
913920

914921
/*
@@ -921,10 +928,8 @@ static bool iomap_write_end(struct iomap_iter *iter, size_t len, size_t copied,
921928
const struct iomap *srcmap = iomap_iter_srcmap(iter);
922929
loff_t pos = iter->pos;
923930

924-
if (srcmap->type == IOMAP_INLINE) {
925-
iomap_write_end_inline(iter, folio, pos, copied);
926-
return true;
927-
}
931+
if (srcmap->type == IOMAP_INLINE)
932+
return iomap_write_end_inline(iter, folio, pos, copied);
928933

929934
if (srcmap->flags & IOMAP_F_BUFFER_HEAD) {
930935
size_t bh_written;

fs/iomap/direct-io.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,9 @@ static int iomap_dio_inline_iter(struct iomap_iter *iomi, struct iomap_dio *dio)
519519
loff_t pos = iomi->pos;
520520
u64 copied;
521521

522+
if (WARN_ON_ONCE(!inline_data))
523+
return -EIO;
524+
522525
if (WARN_ON_ONCE(!iomap_inline_data_valid(iomap)))
523526
return -EIO;
524527

0 commit comments

Comments
 (0)