Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2BD2ACFD2F6 for ; Mon, 24 Nov 2025 02:12:48 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4dF8VQ0h0Jz2yvN; Mon, 24 Nov 2025 13:12:46 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=115.124.30.112 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1763950366; cv=none; b=hKbjujiqlGJTCeJZar7f7/HEkqycuHEyooT3Kb3p/E+qJbSFVw1gVjwtP/TSVensxl2/lCxOrMDMuyX5Sbk8LgFPyADeO0Maiz/Q6jdkqyoTLxsVQoB51RvakqBQa6sljKWRnHxFIFhVAp0QiI8ZPTglJjmPGm8pS4wDTn+5bFgLGtQUAPUVJunf5JwCAnhDNUqw7ddqGsGOLoZM1rWXnx/WDO9yObjbf2SE+7g3OH9e9Yjff9PdQnej/s9jJCLUx76wev9SXO6b+EZgGdfg499YRlOWZTLLrsydegyreZKSs/+8aD1eA/C/s10nE6361Ci6QbFsDE+G8zIZ44XroA== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1763950366; c=relaxed/relaxed; bh=qaEe4P+NeZq5F6dQfgixkx26QzD0xNJvljj20rsl5B4=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=aJf57hFlBXwBi0ZfEZOdRFjyd+4upMu22SLmFV09nwFl78yAsrTm0Q9pl4UbIBpiDjoFdUEWmsH3Q4w0YbieGfQChqGdXWP2OFz6pbcAOX7edTNMG4t1fVX6+JiPu4SWpSbfOCAUhhuVv5HBabPq3nUwG4L1QS4xiXd4z1UyKTQC9uWdxC4nAxd+1WdeSHDkHus4q5ytogoATsUmV/aDMWUxSDsLDRsO0IiIHgDDKtkAQJNbA7XTOXUEovG8Rmc5H02PkvP+sU6pXPk4SGfbwpBBh/HI1yieS+asuZQYCpCqo+GyRQOMTaj4grF9hf693boVwGEJ03ISW/VAZ+DDQQ== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; dkim=pass (1024-bit key; unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=HcJkQ+ei; dkim-atps=neutral; spf=pass (client-ip=115.124.30.112; helo=out30-112.freemail.mail.aliyun.com; envelope-from=hsiangkao@linux.alibaba.com; receiver=lists.ozlabs.org) smtp.mailfrom=linux.alibaba.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=HcJkQ+ei; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.alibaba.com (client-ip=115.124.30.112; helo=out30-112.freemail.mail.aliyun.com; envelope-from=hsiangkao@linux.alibaba.com; receiver=lists.ozlabs.org) Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4dF8VM6pPcz2yvB for ; Mon, 24 Nov 2025 13:12:41 +1100 (AEDT) DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1763950356; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=qaEe4P+NeZq5F6dQfgixkx26QzD0xNJvljj20rsl5B4=; b=HcJkQ+ei1qHdnBG7gV1latjYeKtNTuSJL1zlV+Tb5x2dDoa0TKHYMsHcpbDS7d4X7oct+WAu3NWjFHNJCBL4TyxtAM7+rtifst0f7stu3Xh0TE6I7LRdWGyLv0Uo4WekEdFw/A0d6laSeHSB3d7xIpqzXIoCMs1VT2+kX57O/BM= Received: from 30.221.131.143(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0Wt9f2KY_1763950354 cluster:ay36) by smtp.aliyun-inc.com; Mon, 24 Nov 2025 10:12:35 +0800 Message-ID: Date: Mon, 24 Nov 2025 10:12:33 +0800 X-Mailing-List: linux-erofs@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Subscribe: , , List-Unsubscribe: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] erofs: limit the level of fs stacking for file-backed mounts To: Hongbo Li , linux-erofs@lists.ozlabs.org References: <20251121134647.104354-1-hsiangkao@linux.alibaba.com> <20251122062332.1408580-1-hsiangkao@linux.alibaba.com> <058b9c29-6e07-4661-8b83-b05d8762b524@huawei.com> From: Gao Xiang In-Reply-To: <058b9c29-6e07-4661-8b83-b05d8762b524@huawei.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2025/11/24 10:03, Hongbo Li wrote: > Hi Xiang, > > On 2025/11/22 14:23, Gao Xiang wrote: >> 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 >> --- >> 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) >>       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"); > > Since it will success once the max stack depth is exceeded, a warning would be better? Otherwise it looks good me. But that is not a kernel fallback, and the kernel mount already fails, I think erroring out is more proper. Thanks, Gao Xiang > > Reviewed-by: Hongbo Li > > Thanks, > Hongbo > >> +                return -ENOTBLK; >> +            } >> +        } >>           sb->s_blocksize = PAGE_SIZE; >>           sb->s_blocksize_bits = PAGE_SHIFT;