Commit d53cd891 authored by Gao Xiang's avatar Gao Xiang
Browse files

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: default avatarSheng Yong <shengyong1@xiaomi.com>
Fixes: fb176750 ("erofs: add file-backed mount support")
Reviewed-by: default avatarChao Yu <chao@kernel.org>
Reviewed-by: default avatarHongbo Li <lihongbo22@huawei.com>
Signed-off-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
parent ebe4f3f6
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -639,6 +639,22 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)

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