iomap: reject delalloc mappings during writeback
Subsystems (2)
PATCH 1/1 iomap: reject delalloc mappings during writeback
From: Darrick J. Wong <[email protected]>
Filesystems should never provide a delayed allocation mapping to writeback; they're supposed to allocate the space before replying. This can lead to weird IO errors and crashes in the block layer if the filesystem is being malicious, or if it hadn't set iomap->dev because it's a delalloc mapping.
Fix this by failing writeback on delalloc mappings. Currently no filesystems actually misbehave in this manner, but we ought to be stricter about things like that.
--- fs/iomap/ioend.c | 1 + 1 file changed, 1 insertion(+)
fs/iomap/ioend.c +1 -0
@@ -216,6 +216,7 @@ ssize_t iomap_add_to_ioend(struct iomap_writepage_ctx *wpc, struct folio *folio,switch (wpc->iomap.type) {case IOMAP_INLINE : +case IOMAP_DELALLOC :WARN_ON_ONCE (1 );return -EIO ;case IOMAP_HOLE :
Quoted 11 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Filesystems should never provide a delayed allocation mapping to writeback; they're supposed to allocate the space before replying. This can lead to weird IO errors and crashes in the block layer if the filesystem is being malicious, or if it hadn't set
iomap->devbecause it's a delalloc mapping.Fix this by failing writeback on delalloc mappings. Currently no filesystems actually misbehave in this manner, but we ought to be stricter about things like that.
Maybe switch to to explicitly listing the acceptable types and rejecting the rest instead?
fs/iomap/ioend.c +7 -6
@@ -169,17 +169,18 @@ ssize_t iomap_add_to_ioend(struct iomap_writepage_ctx *wpc, struct folio *folio,WARN_ON_ONCE (!folio->private && map_len < dirty_len);switch (wpc->iomap.type) { -case IOMAP_INLINE : -WARN_ON_ONCE (1 ); -return -EIO ; +case IOMAP_UNWRITTEN : + ioend_flags |=IOMAP_IOEND_UNWRITTEN ; + fallthrough; +case IOMAP_MAPPED : +break ;case IOMAP_HOLE :return map_len;default : -break ; +WARN_ON_ONCE (1 ); +return -EIO ; } -if (wpc->iomap.type ==IOMAP_UNWRITTEN ) - ioend_flags |=IOMAP_IOEND_UNWRITTEN ;if (wpc->iomap.flags &IOMAP_F_SHARED ) ioend_flags |=IOMAP_IOEND_SHARED ;if (folio_test_dropbehind (folio))
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Filesystems should never provide a delayed allocation mapping to writeback; they're supposed to allocate the space before replying. This can lead to weird IO errors and crashes in the block layer if the filesystem is being malicious, or if it hadn't set
iomap->devbecause it's a delalloc mapping.
Quoted 6 lines
Quoted 3 lines
Fix this by failing writeback on delalloc mappings. Currently no filesystems actually misbehave in this manner, but we ought to be stricter about things like that.
Maybe switch to to explicitly listing the acceptable types and rejecting the rest instead?
Yeah, that's a better solution, particularly if we ever add a new mapping type.
--D
Quoted 30 lines
fs/iomap/ioend.c +7
-6@@ -169,17 +169,18 @@ ssize_t iomap_add_to_ioend(struct iomap_writepage_ctx *wpc, struct folio *folio,WARN_ON_ONCE (!folio->private && map_len < dirty_len);switch (wpc->iomap.type) { -case IOMAP_INLINE : -WARN_ON_ONCE (1 ); -return -EIO ; +case IOMAP_UNWRITTEN : + ioend_flags |=IOMAP_IOEND_UNWRITTEN ; + fallthrough; +case IOMAP_MAPPED : +break ;case IOMAP_HOLE :return map_len;default : -break ; +WARN_ON_ONCE (1 ); +return -EIO ; } -if (wpc->iomap.type ==IOMAP_UNWRITTEN ) - ioend_flags |=IOMAP_IOEND_UNWRITTEN ;if (wpc->iomap.flags &IOMAP_F_SHARED ) ioend_flags |=IOMAP_IOEND_SHARED ;if (folio_test_dropbehind (folio))