From nobody Tue Dec 2 01:30:19 2025 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) (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 9BA4433CE92 for ; Fri, 21 Nov 2025 13:47:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763732824; cv=none; b=dRjxZNR1o6xm/ybElPV+ynsbLGOrtRCnjTyGbFBWCjOTOt6WOxr7oeIEr2wd9hRKkmz9U/urqySYPeU2sSYA/Cq37pCYKPNMmufD6Ois7pM2D/XYo7/pfe6v0d7IKTklpVUpp6Tu+vh3ovsjhhxbvZGD2jkE1r37dAKLmydghU0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763732824; c=relaxed/simple; bh=uvRrdabzGkCwQcI+w81vzJtGJRj/SGgBa4kgX+8htE4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=EBZCH0iTyxbt6opL3XWli39L6tsFrDpaWEhdgG0j7MMnhl7hR5r4hmABuhYpFdDCpsTsDL+xG9M+623lLJ6JVAVpi60jZvCa9RhgX+KJ4U12dLQ4tUZbJQubRANr9omR3KH3diZijbtIXl7wRY9zUSHYKiQ4rZGOzdiVZoqlYr0= 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=oZlF5qnq; arc=none smtp.client-ip=115.124.30.100 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="oZlF5qnq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1763732812; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=VKBiilkgZg/0HYkeoJzPUZ4zUqJFiuQQlGJ8QWzSh0c=; b=oZlF5qnqi9mCsPP6tKmUM3eXeIPW6AdQVcBz3UrYp35S6oypa6hrTJ27FvRAgcECIE6qS9Vj3UxnbHaApy2kQnwHOBpc7xWwuw/qbvD05aKpr4Bl0g292TNTtcysMswUxPchJdEqY9IzqsPlhnEuo/HcYnDEG/lmZ5jVHT1+47Q= Received: from x31i01179.sqa.na131.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0Wt0FHJz_1763732808 cluster:ay36) by smtp.aliyun-inc.com; Fri, 21 Nov 2025 21:46:52 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org Cc: LKML , Christian Brauner , Gao Xiang Subject: [PATCH] erofs: limit the level of fs stacking for file-backed mounts Date: Fri, 21 Nov 2025 21:46:47 +0800 Message-ID: <20251121134647.104354-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 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). Fixes: fb176750266a ("erofs: add file-backed mount support") Signed-off-by: Gao Xiang Reviewed-by: Sheng Yong --- fs/erofs/super.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index f3f8d8c066e4..d408921d74d0 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 -EINVAL; + } + } sb->s_blocksize =3D PAGE_SIZE; sb->s_blocksize_bits =3D PAGE_SHIFT; =20 --=20 2.43.5