Skip to contentSkip to conversation

erofs: Fix the slab-out-of-bounds in drop_buffers()

PATCH In review Denis Arefev 2 participants 4 messages Mar 23 Stable branch

lore
Share & tools
lore
#0 lore raw

cover erofs: Fix the slab-out-of-bounds in drop_buffers()

Syzbot reported that a KASAN slab-out-of-bounds bug was discovered in the drop_buffers() function [1].

The root cause is that erofs_raw_access_aops does not define .release_folio and .invalidate_folio. When using iomap-based operations, folio->private may contain iomap-specific data rather than buffer_heads. Without special handlers, the kernel may fall back to generic functions (e.g., drop_buffers), which incorrectly treat folio->private as a list of buffer_head structures, leading to incorrect memory interpretation and out-of-bounds access.

This can be fixed by explicitly setting .release_folio and .invalidate_folio to iomap_release_folio and iomap_invalidate_folio, respectively, but there is a commit ce529cc25b184e93397b94a8a322128fc0095cbb in upstream that implicitly fixes this bug.

Please commit it to the stable branch v6.1.y .

[1] https://syzkaller.appspot.com/bug?id=c6aeabd0c4ad2466f63a274faf2a123103f8fbf7

Jingbo Xu (1):
erofs: enable large folios for iomap mode

 fs/erofs/data.c  | 2 ++
 fs/erofs/inode.c | 2 ++
 2 files changed, 4 insertions(+)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/1 erofs: enable large folios for iomap mode

From: Jingbo Xu <[email protected]>

commit ce529cc25b184e93397b94a8a322128fc0095cbb upstream.

Enable large folios for iomap mode. Then the readahead routine will pass down large folios containing multiple pages.

Let's enable this for non-compressed format for now, until the compression part supports large folios later.

When large folios supported, the iomap routine will allocate iomap_page for each large folio and thus we need iomap_release_folio() and iomap_invalidate_folio() to free iomap_page when these folios get reclaimed or invalidated.

---

---
 fs/erofs/data.c  | 2 ++
 fs/erofs/inode.c | 2 ++
 2 files changed, 4 insertions(+)
fs/erofs/data.c +2 -0
index fe8ac0e163f7..c9526c627dda 100644
@@ -403,6 +403,8 @@ const struct address_space_operations erofs_raw_access_aops = {
 	.readahead = erofs_readahead,
 	.bmap = erofs_bmap,
 	.direct_IO = noop_direct_IO,
+	.release_folio = iomap_release_folio,
+	.invalidate_folio = iomap_invalidate_folio,
 };
 
 #ifdef CONFIG_FS_DAX
fs/erofs/inode.c +2 -0
index ad2a82f2eb4c..e457b8a59ee7 100644
@@ -295,6 +295,8 @@ static int erofs_fill_inode(struct inode *inode)
 		goto out_unlock;
 	}
 	inode->i_mapping->a_ops = &erofs_raw_access_aops;
+	if (!erofs_is_fscache_mode(inode->i_sb))
+		mapping_set_large_folios(inode->i_mapping);
 #ifdef CONFIG_EROFS_FS_ONDEMAND
 	if (erofs_is_fscache_mode(inode->i_sb))
 		inode->i_mapping->a_ops = &erofs_fscache_access_aops;
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 6.1 1/1] erofs: enable large folios for iomap mode

Hi Denis,

Quoted 15 lines · Denis Arefev

From: Jingbo Xu <[email protected]>

commit ce529cc25b184e93397b94a8a322128fc0095cbb upstream.

Enable large folios for iomap mode. Then the readahead routine will pass down large folios containing multiple pages.

Let's enable this for non-compressed format for now, until the compression part supports large folios later.

When large folios supported, the iomap routine will allocate iomap_page for each large folio and thus we need iomap_release_folio() and iomap_invalidate_folio() to free iomap_page when these folios get reclaimed or invalidated.

Quoted 6 lines

I think we have no plan to enable large folios for Linux 6.1 kernels, if the following part is what you need, how about just backporting the following snippet with the updated commit message for some explanation:

fs/erofs/data.c const struct address_space_operations erofs_raw_access_aops = { · line 407

Quoted 2 lines
fs/erofs/data.c +2 -0
+	.release_folio = iomap_release_folio,
+	.invalidate_folio = iomap_invalidate_folio,

Thanks,
Gao Xiang

#3 lore raw
In reply to Denis Arefev

Hi Denis,

Quoted 10 lines · Denis Arefev

Syzbot reported that a KASAN slab-out-of-bounds bug was discovered in the drop_buffers() function [1].

The root cause is that erofs_raw_access_aops does not define .release_folio and .invalidate_folio. When using iomap-based operations, folio->private may contain iomap-specific data rather than buffer_heads. Without special handlers, the kernel may fall back to generic functions (e.g., drop_buffers), which incorrectly treat folio->private as a list of buffer_head structures, leading to incorrect memory interpretation and out-of-bounds access.

Quoted 4 lines

This can be fixed by explicitly setting .release_folio and .invalidate_folio to iomap_release_folio and iomap_invalidate_folio, respectively, but there is a commit ce529cc25b184e93397b94a8a322128fc0095cbb in upstream that implicitly fixes this bug.

See my previous reply to the patch.

Thanks,
Gao Xiang

Quoted 12 lines

Please commit it to the stable branch v6.1.y .

[1] https://syzkaller.appspot.com/bug?id=c6aeabd0c4ad2466f63a274faf2a123103f8fbf7

Jingbo Xu (1):
erofs: enable large folios for iomap mode

  fs/erofs/data.c  | 2 ++
  fs/erofs/inode.c | 2 ++
  2 files changed, 4 insertions(+)