From patchwork Fri Mar 24 12:16:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 13186701 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DD31C6FD1C for ; Fri, 24 Mar 2023 12:16:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231263AbjCXMQS (ORCPT ); Fri, 24 Mar 2023 08:16:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230382AbjCXMQR (ORCPT ); Fri, 24 Mar 2023 08:16:17 -0400 Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EE2A6A40 for ; Fri, 24 Mar 2023 05:16:15 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 3EB9E6431C29; Fri, 24 Mar 2023 13:16:13 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id U883YgBzBaX7; Fri, 24 Mar 2023 13:16:12 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id E074E605DED8; Fri, 24 Mar 2023 13:16:12 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id KJtiBfdg335F; Fri, 24 Mar 2023 13:16:12 +0100 (CET) Received: from blindfold.corp.sigma-star.at (213-47-184-186.cable.dynamic.surfer.at [213.47.184.186]) by lithops.sigma-star.at (Postfix) with ESMTPSA id 8FA4A6431C29; Fri, 24 Mar 2023 13:16:12 +0100 (CET) From: Richard Weinberger To: steved@redhat.com Cc: trond.myklebust@hammerspace.com, linux-nfs@vger.kernel.org, chris.chilvers@appsbroker.com, Richard Weinberger Subject: [PATCH] export: Fix rootdir corner case in next_mnt() Date: Fri, 24 Mar 2023 13:16:08 +0100 Message-Id: <20230324121608.16808-1-richard@nod.at> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Currently the following setup causes failure: 1. /etc/exports: / *(rw,crossmnt,no_subtree_check,fsid=root) 2. /etc/nfs.conf: [exports] rootdir=/nfs_srv 3. Mounts: /root/fs1.ext4 on /nfs_srv type ext4 (rw,relatime) /root/fs2.ext4 on /nfs_srv/fs2 type ext4 (rw,relatime) 4. On the client: $ ls /nfs_client/fs2 ls: cannot open directory '/nfs_client/fs2': Stale file handle The problem is that next_mnt() misses the corner case that every mount is a sub-mount of "/". So it fails to see that /nfs_srv/fs2 is a mountpoint when the client asks for fs2 it and as consequence the crossmnt mechanism fails. Signed-off-by: Richard Weinberger --- support/export/cache.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/support/export/cache.c b/support/export/cache.c index 2497d4f48df3..1c526277d3c6 100644 --- a/support/export/cache.c +++ b/support/export/cache.c @@ -410,12 +410,16 @@ static char *next_mnt(void **v, char *p) *v = f; } else f = *v; - while ((me = getmntent(f)) != NULL && l > 1) { + while ((me = getmntent(f)) != NULL && l >= 1) { char *mnt_dir = nfsd_path_strip_root(me->mnt_dir); if (!mnt_dir) continue; + /* Everything below "/" is a proper sub-mount */ + if (strcmp(p, "/") == 0) + return mnt_dir; + if (strncmp(mnt_dir, p, l) == 0 && mnt_dir[l] == '/') return mnt_dir; }