* [PATCH v2 0/2] nfsd: enforce search permission on directory delegations without breaking stat() @ 2026-11-24 18:06 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 ` [PATCH v2 2/2] nfsd: require NFSD_MAY_EXEC when acquiring directory delegations Dominik Maier 0 siblings, 2 replies; 5+ 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 Enforce NFSD_MAY_EXEC (and limit NFSD_MAY_OWNER_OVERRIDE to S_IFREG) when acquiring directory delegations, preceded by returning GDD4_UNAVAIL on nfsd_file_acquire_dir() failure so Linux NFS clients issuing PUTFH + GET_DIR_DELEGATION + GETATTR do not fail stat() with EACCES on directories lacking read or search permission. Changes in v2: - Add patch 1/2 returning NFS4_OK with GDD4_UNAVAIL when nfsd_file_acquire_dir() fails (Chuck Lever). - Add Jeff Layton's Reviewed-by on patch 2/2, keep the single root Fixes: 544a0ee152f0 tag, and drop the commit-body tool boilerplate. - v1: https://lore.kernel.org/linux-nfs/20261119192318.2689409-1-dmnk@google.com/ Patch 2/2 was found with AI-assisted code review and reproduced against an unmodified kernel in QEMU; the v2 series is based on nfsd-testing. Dominik Maier (2): nfsd: return GDD4_UNAVAIL when nfsd_file_acquire_dir() fails nfsd: require NFSD_MAY_EXEC when acquiring directory delegations fs/nfsd/filecache.c | 10 ++++++---- fs/nfsd/nfs4proc.c | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) -- 2.56.1.831.g720f3f5937-goog ^ permalink raw reply [flat|nested] 5+ messages in thread
* [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 20:02 ` Jeff Layton 2026-11-24 18:06 ` [PATCH v2 2/2] nfsd: require NFSD_MAY_EXEC when acquiring directory delegations Dominik Maier 1 sibling, 2 replies; 5+ 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] 5+ messages in thread
* Re: [PATCH v2 1/2] nfsd: return GDD4_UNAVAIL when nfsd_file_acquire_dir() fails 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 20:02 ` Jeff Layton 1 sibling, 0 replies; 5+ messages in thread From: Chuck Lever @ 2026-11-24 19:45 UTC (permalink / raw) To: Dominik Maier, Jeff Layton Cc: NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey, linux-nfs, dmnk+artist > 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. Yes, please narrow it. My snippet was too broad. > 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; > + } nfsd_file_acquire_dir() verifies the filehandle with S_IFDIR, so a GET_DIR_DELEGATION on a regular file fails here with nfserr_notdir. RFC 8881 lists NFS4ERR_NOTDIR for this operation. With this change, NFSD replies NFS4_OK to a client that asks for a delegation on a regular file. The empty-filehandle case is less obvious. Both retry paths in nfsd_file_do_acquire() call fh_put() on cstate->current_fh before they call fh_verify() again. If that second fh_verify() fails (say, nfserr_stale after a racing unlink), current_fh.fh_dentry is NULL when this function returns nfs_ok. Doesn't the trailing GETATTR then fail with NFS4ERR_NOFILEHANDLE, rather than GET_DIR_DELEGATION reporting the stale handle? Testing for nfserr_acces covers both cases. __fh_verify() calls nfsd_set_fh_dentry() before nfsd_permission(), so an nfserr_acces always comes back with fh_dentry set: if (status == nfserr_acces) { gdd->gddrnf_status = GDD4_UNAVAIL; return nfs_ok; } if (status != nfs_ok) return status; -- Chuck Lever ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] nfsd: return GDD4_UNAVAIL when nfsd_file_acquire_dir() fails 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 20:02 ` Jeff Layton 1 sibling, 0 replies; 5+ messages in thread From: Jeff Layton @ 2026-11-24 20:02 UTC (permalink / raw) To: Dominik Maier, Chuck Lever Cc: NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey, linux-nfs, dmnk+artist On Tue, 2026-11-24 at 18:06 +0000, Dominik Maier wrote: > 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 Nice catch! Reviewed-by: Jeff Layton <jlayton@kernel.org> ^ permalink raw reply [flat|nested] 5+ 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; 5+ 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] 5+ messages in thread
end of thread, other threads:[~2026-11-24 20:02 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 20:02 ` Jeff Layton 2026-11-24 18:06 ` [PATCH v2 2/2] nfsd: require NFSD_MAY_EXEC when acquiring directory delegations Dominik Maier
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.