From nobody Tue Dec 2 01:05:37 2025 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92BEC246783 for ; Sat, 22 Nov 2025 06:23:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.113 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763792634; cv=none; b=m2WcCUhPPof/KCz/oeVkWvXzQUdpnT4nelFMBhcNbgebW4XQpPwH2Fh0XiqeGEMcoDxTbfDtpwnQoU5C7BXI3RBv4gLSGaNhUK2iMrS0vSYt9Rrpk9bTig/Rgw4hXaYZdQhMwFunkIEOkKx/6y/QUg2HfzYkyc3JrAgKbNYjq3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763792634; c=relaxed/simple; bh=DmURdJUkY4yon/N0YZ5mJJBN3pQTeqRC/ZGiMYFhKh4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pSUJGm1Yo9BwMLUav8CW/nUu+H3yaV7O1QUd4aHT9SKjgUFpxLfnvq91kBHUxbM6UwtHp6Pu+HOo8iRxeF5XxwnO5GMuBPkU8puzXn4kP9im2mWJs2UQ2agZjJALTXQH4WzxmQupDo/Mokp7AFj+7Mnd0QIlKrNQDIPzjDxgnb8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=uXBLKLl9; arc=none smtp.client-ip=115.124.30.113 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="uXBLKLl9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1763792621; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=BtUfsyquN9hxwRTgOZsv8MVWTwMe9z1a+cT1ilPEt98=; b=uXBLKLl9WRJp1cfn8/Tfqn1WwKjTh93iivGXKRGuNvMvd2K+SVp4Mqmj6hUsjG61nEmtZf62z2d+HJ+MSX36T4Ko5PeAKd1uC1n9f16j4tcyvOOW7bfsv+OD2kipYIEoDnxF+uYR55NdG/0gHtCN0DG5NKKxE8sF4Z1go57D3TE= Received: from x31i01179.sqa.na131.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0Wt3AgA3_1763792614 cluster:ay36) by smtp.aliyun-inc.com; Sat, 22 Nov 2025 14:23:40 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org Cc: LKML , Christian Brauner , Jan Kara , Gao Xiang , Sheng Yong Subject: [PATCH v2] erofs: limit the level of fs stacking for file-backed mounts Date: Sat, 22 Nov 2025 14:23:32 +0800 Message-ID: <20251122062332.1408580-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251121134647.104354-1-hsiangkao@linux.alibaba.com> References: <20251121134647.104354-1-hsiangkao@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Otherwise, it could cause potential kernel stack overflow (e.g., EROFS mounting itself). Reviewed-by: Sheng Yong Fixes: fb176750266a ("erofs: add file-backed mount support") Signed-off-by: Gao Xiang Reviewed-by: Chao Yu --- Change since v1: - Return -ENOTBLK instead of -EINVAL since userspace tools like util-linux will fall back to using loop to mount again. Don't use -ELOOP compared to other stacked fses, since -ENOTBLK is more suitable: it means the kernel can't handle it anymore. fs/erofs/super.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index f3f8d8c066e4..2db534f76464 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -639,6 +639,22 @@ static int erofs_fc_fill_super(struct super_block *sb,= struct fs_context *fc) =20 sbi->blkszbits =3D 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 =3D + 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 =3D PAGE_SIZE; sb->s_blocksize_bits =3D PAGE_SHIFT; =20 --=20 2.43.5