Skip to content

Commit d53cd89

Browse files
committed
erofs: limit the level of fs stacking for file-backed mounts
Otherwise, it could cause potential kernel stack overflow (e.g., EROFS mounting itself). Reviewed-by: Sheng Yong <shengyong1@xiaomi.com> Fixes: fb17675 ("erofs: add file-backed mount support") Reviewed-by: Chao Yu <chao@kernel.org> Reviewed-by: Hongbo Li <lihongbo22@huawei.com> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
1 parent ebe4f3f commit d53cd89

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

fs/erofs/super.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,22 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
639639

640640
sbi->blkszbits = PAGE_SHIFT;
641641
if (!sb->s_bdev) {
642+
/*
643+
* (File-backed mounts) EROFS claims it's safe to nest other
644+
* fs contexts (including its own) due to self-controlled RO
645+
* accesses/contexts and no side-effect changes that need to
646+
* context save & restore so it can reuse the current thread
647+
* context. However, it still needs to bump `s_stack_depth` to
648+
* avoid kernel stack overflow from nested filesystems.
649+
*/
650+
if (erofs_is_fileio_mode(sbi)) {
651+
sb->s_stack_depth =
652+
file_inode(sbi->dif0.file)->i_sb->s_stack_depth + 1;
653+
if (sb->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) {
654+
erofs_err(sb, "maximum fs stacking depth exceeded");
655+
return -ENOTBLK;
656+
}
657+
}
642658
sb->s_blocksize = PAGE_SIZE;
643659
sb->s_blocksize_bits = PAGE_SHIFT;
644660

0 commit comments

Comments
 (0)