Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp584753iog; Wed, 29 Jun 2022 06:23:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uaAjiMe2a3s4/xGD+lVavRUVtzjRMIrHSoOB0IQTPe1yfWcElNYMpWixTYEiaFh3dHOabX X-Received: by 2002:a17:90b:1c01:b0:1ed:4b98:2499 with SMTP id oc1-20020a17090b1c0100b001ed4b982499mr5978262pjb.90.1656508997707; Wed, 29 Jun 2022 06:23:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656508997; cv=none; d=google.com; s=arc-20160816; b=SQfumtffUiAseeOjqelU6eCiCRNl9GMd2KjmEPuY0n/5Gzhnn4FmFYKOokX59gwC6f 9vMYVUmfNGjGL5ON5PUIHfjlJNJrD+yDHMU79e9jWmtRuKcQH+YYOxAvL4rHIia9F0YK V5nSsDGIZeLiqPWBRxp/tNvBkKa4ESIR+OThBGX5HXDflv5VgW7WUE03ghie6OWhWiXZ lI5AKk2itsPaQuMGb/Sild0gBnluDO9XG/rspNpP7Fq34+/rsqTGKhKpUa/fznEdqUwY Ofr73c3c83m/HjMzNIbmoEtP6KmYnDtjAe97wGiCQiGTImyIHGQEiNHTSqjLoVHAihXH /B/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=YUkgEt0K62ScmzuF42Ys/ZHy08zd+2uIQz6JEvp/FYk=; b=Hdegel5aL4mbvSfUp9kpF7Fx2Xfho9fOzA9j6pAvTPQY+L5OcIqHQSyGpQIK3mT5Mm Vs2dA4g7SbUeGhXfriP8AsLvAnksIRrEZmsngzxkvYCVKaGQZTCwi9o+pOjC7tCB8cWE 3lIIQ9C0WFIyvvt+mo3If30mpXuz8oScSP/CTioMIcUUgSHpw9qV5iDz11xduuQ92gCE buttdYiWgDTpia6elItPe7d7MQhwIhm+aT+ueFKf4gEkhnfNEArrpFToGJG1c5488yDt nZIAPl2qyuFq1AxMgdDc8J9B4QY0MBzvtQt+kV23J2ab3P2p6+n3Lsch6yJafIb4UBoi QpTg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g130-20020a636b88000000b0040dbb3c4c1esi16746249pgc.567.2022.06.29.06.23.01; Wed, 29 Jun 2022 06:23:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233320AbiF2Mey (ORCPT + 99 others); Wed, 29 Jun 2022 08:34:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233055AbiF2Mew (ORCPT ); Wed, 29 Jun 2022 08:34:52 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72311255A0 for ; Wed, 29 Jun 2022 05:34:46 -0700 (PDT) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LY16B6BK8zTgCQ; Wed, 29 Jun 2022 20:31:14 +0800 (CST) Received: from dggpemm100009.china.huawei.com (7.185.36.113) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 29 Jun 2022 20:34:45 +0800 Received: from huawei.com (10.175.101.6) by dggpemm100009.china.huawei.com (7.185.36.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 29 Jun 2022 20:34:44 +0800 From: ZhaoLong Wang To: , CC: , , , , , Subject: [PATCH -next,v2] tmpfs: Fix the issue that the mount and remount results are inconsistent. Date: Wed, 29 Jun 2022 20:43:24 +0800 Message-ID: <20220629124324.1640807-1-wangzhaolong1@huawei.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100009.china.huawei.com (7.185.36.113) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org An undefined-behavior issue has not been completely fixed since commit d14f5efadd84 ("tmpfs: fix undefined-behaviour in shmem_reconfigure()"). In the commit, check in the shmem_reconfigure() is added in remount process to avoid the Ubsan problem. However, the check is not added to the mount process.It cause the inconsistent results between mount and remount. The operations to reproduce the problem in user mode as follow: If nr_blocks is set to 0x8000000000000000, the mounting is successful. # mount tmpfs /dev/shm/ -t tmpfs -o nr_blocks=0x8000000000000000 However, when -o remount is used, the mount fails because of the check in the shmem_reconfigure() # mount tmpfs /dev/shm/ -t tmpfs -o remount,nr_blocks=0x8000000000000000 mount: /dev/shm: mount point not mounted or bad option. Therefore, add checks in the shmem_parse_one() function and remove the check in shmem_reconfigure() to avoid this problem. Signed-off-by: ZhaoLong Wang --- mm/shmem.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index a6f565308133..b7f2d4a56867 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3392,7 +3392,7 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param) break; case Opt_nr_blocks: ctx->blocks = memparse(param->string, &rest); - if (*rest) + if (*rest || ctx->blocks > S64_MAX) goto bad_value; ctx->seen |= SHMEM_SEEN_BLOCKS; break; @@ -3514,10 +3514,7 @@ static int shmem_reconfigure(struct fs_context *fc) raw_spin_lock(&sbinfo->stat_lock); inodes = sbinfo->max_inodes - sbinfo->free_inodes; - if (ctx->blocks > S64_MAX) { - err = "Number of blocks too large"; - goto out; - } + if ((ctx->seen & SHMEM_SEEN_BLOCKS) && ctx->blocks) { if (!sbinfo->max_blocks) { err = "Cannot retroactively limit size"; -- 2.31.1