Linux NFS development
 help / color / mirror / Atom feed
From: Dominik Maier <dmnk@google.com>
To: Chuck Lever <cel@kernel.org>, Jeff Layton <jlayton@kernel.org>
Cc: NeilBrown <neil@brown.name>,
	Olga Kornievskaia <okorniev@redhat.com>,
	Dai Ngo <Dai.Ngo@oracle.com>,  Tom Talpey <tom@talpey.com>,
	linux-nfs@vger.kernel.org, dmnk+artist@google.com
Subject: [PATCH v2 2/2] nfsd: require NFSD_MAY_EXEC when acquiring directory delegations
Date: Tue, 24 Nov 2026 18:06:06 +0000	[thread overview]
Message-ID: <20261124180606.73719-3-dmnk@google.com> (raw)
In-Reply-To: <20261124180606.73719-1-dmnk@google.com>

nfsd_file_acquire_dir() opens a directory for nfsd4_get_dir_delegation()
with NFSD_MAY_READ | NFSD_MAY_64BIT_COOKIE, omitting NFSD_MAY_EXEC, and
nfsd_file_do_acquire() unconditionally sets NFSD_MAY_OWNER_OVERRIDE even
for S_IFDIR (unlike nfsd_open(), which limits it to S_IFREG).

On a directory with read permission but no search permission (such as
mode 0744 for a non-owner, or mode 0400 / ACL-denied search for the
owner), an NFSv4.1 client can still acquire a directory delegation with
NOTIFY4_ADD_ENTRY and FATTR4_WORD0_FILEHANDLE and receive valid child
filehandles in CB_NOTIFY callbacks when entries are created, despite
LOOKUP returning NFS4ERR_ACCESS.

Require NFSD_MAY_EXEC in nfsd_file_acquire_dir() and restrict
NFSD_MAY_OWNER_OVERRIDE in nfsd_file_do_acquire() to S_IFREG, matching
nfsd_open().

Fixes: 544a0ee152f0 ("nfsd: allow filecache to hold S_IFDIR files")
Cc: stable@vger.kernel.org
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Dominik Maier <dmnk@google.com>
---
 fs/nfsd/filecache.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c
index 162d07eb5be4..a703d376a52f 100644
--- a/fs/nfsd/filecache.c
+++ b/fs/nfsd/filecache.c
@@ -1197,13 +1197,14 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct net *net,
 	__be32 status;
 	int ret;
 
+	if (type == S_IFREG)
+		may_flags |= NFSD_MAY_OWNER_OVERRIDE;
 retry:
 	if (rqstp)
-		status = fh_verify(rqstp, fhp, type,
-				   may_flags|NFSD_MAY_OWNER_OVERRIDE);
+		status = fh_verify(rqstp, fhp, type, may_flags);
 	else
 		status = fh_verify_local(net, cred, client, fhp, type,
-					 may_flags|NFSD_MAY_OWNER_OVERRIDE);
+					 may_flags);
 
 	if (status != nfs_ok)
 		return status;
@@ -1475,7 +1476,8 @@ nfsd_file_acquire_dir(struct svc_rqst *rqstp, struct svc_fh *fhp,
 		      struct nfsd_file **pnf)
 {
 	return nfsd_file_do_acquire(rqstp, SVC_NET(rqstp), NULL, NULL, fhp,
-				    NFSD_MAY_READ|NFSD_MAY_64BIT_COOKIE,
+				    NFSD_MAY_READ | NFSD_MAY_EXEC |
+				    NFSD_MAY_64BIT_COOKIE,
 				    NULL, S_IFDIR, false, pnf);
 }
 
-- 
2.56.1.831.g720f3f5937-goog


      parent reply	other threads:[~2026-11-24 18:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 18:06 [PATCH v2 0/2] nfsd: enforce search permission on directory delegations without breaking stat() Dominik Maier
2026-11-24 18:06 ` [PATCH v2 1/2] nfsd: return GDD4_UNAVAIL when nfsd_file_acquire_dir() fails Dominik Maier
2026-11-24 19:45   ` Chuck Lever
2026-11-24 18:06 ` Dominik Maier [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261124180606.73719-3-dmnk@google.com \
    --to=dmnk@google.com \
    --cc=Dai.Ngo@oracle.com \
    --cc=cel@kernel.org \
    --cc=dmnk+artist@google.com \
    --cc=jlayton@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neil@brown.name \
    --cc=okorniev@redhat.com \
    --cc=tom@talpey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox