* [PATCH v2 1/2] nfsd: return GDD4_UNAVAIL when nfsd_file_acquire_dir() fails
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 ` Dominik Maier
2026-11-24 19:45 ` Chuck Lever
2026-11-24 18:06 ` [PATCH v2 2/2] nfsd: require NFSD_MAY_EXEC when acquiring directory delegations Dominik Maier
1 sibling, 1 reply; 4+ messages in thread
From: Dominik Maier @ 2026-11-24 18:06 UTC (permalink / raw)
To: Chuck Lever, Jeff Layton
Cc: NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey, linux-nfs,
dmnk+artist
The Linux NFS client requests a directory delegation by inserting
GET_DIR_DELEGATION between PUTFH and GETATTR in a single COMPOUND, and
_nfs4_proc_getattr() does not tolerate -EACCES. When
nfsd_file_acquire_dir() fails (for example for a non-owner doing stat()
on a mode 0711 directory without read permission), returning the error
aborts the COMPOUND before GETATTR and surfaces EACCES to stat().
Reply NFS4_OK with GDD4_UNAVAIL when nfsd_file_acquire_dir() fails,
matching the non-fatal nfsd_get_dir_deleg() path below so the delegation
is withheld while the trailing GETATTR still completes.
Fixes: 8b99f6a8c116 ("nfsd: wire up GET_DIR_DELEGATION handling")
Cc: stable@vger.kernel.org
Suggested-by: Chuck Lever <cel@kernel.org>
Signed-off-by: Dominik Maier <dmnk@google.com>
---
Note: matching your snippet, this folds any nfsd_file_acquire_dir()
error into GDD4_UNAVAIL; let me know if you prefer narrowing it to
status == nfserr_acces so errors like NFS4ERR_NOTDIR or NFS4ERR_WRONGSEC
still surface directly.
fs/nfsd/nfs4proc.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index b76320c265e1..dd17a6b47222 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -2873,8 +2873,10 @@ nfsd4_get_dir_delegation(struct svc_rqst *rqstp,
__be32 status;
status = nfsd_file_acquire_dir(rqstp, &cstate->current_fh, &nf);
- if (status != nfs_ok)
- return status;
+ if (status != nfs_ok) {
+ gdd->gddrnf_status = GDD4_UNAVAIL;
+ return nfs_ok;
+ }
/*
* Offer no notifications to an order-aware client. RFC8881bis section
--
2.56.1.831.g720f3f5937-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 2/2] nfsd: require NFSD_MAY_EXEC when acquiring directory delegations
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 18:06 ` Dominik Maier
1 sibling, 0 replies; 4+ messages in thread
From: Dominik Maier @ 2026-11-24 18:06 UTC (permalink / raw)
To: Chuck Lever, Jeff Layton
Cc: NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey, linux-nfs,
dmnk+artist
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
^ permalink raw reply related [flat|nested] 4+ messages in thread