* [PATCH v3 0/2] nfsd: enforce search permission on directory delegations
@ 2026-11-30 16:04 Dominik Maier
2026-11-30 16:04 ` [PATCH v3 1/2] nfsd: return GDD4_UNAVAIL on nfserr_acces in nfsd4_get_dir_delegation() Dominik Maier
2026-11-30 16:04 ` [PATCH v3 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-30 16:04 UTC (permalink / raw)
To: Chuck Lever, Jeff Layton
Cc: NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey, linux-nfs,
dmnk+artist
Clients can currently acquire NFSv4.1 directory delegations on
directories they can read but not search, receiving child filehandles in
CB_NOTIFY despite LOOKUP failing with NFS4ERR_ACCESS.
Patch 1 declines directory delegations with GDD4_UNAVAIL on access
denial so compound PUTFH + GET_DIR_DELEGATION + GETATTR requests on mode
0711 directories continue to succeed, while surfacing non-directory and
stale-filehandle errors directly. Patch 2 enforces search permission and
limits the owner permission override to regular files.
Changes in v3:
- Only map nfserr_acces to GDD4_UNAVAIL in patch 1/2 (Chuck Lever).
- Add Jeff Layton's Reviewed-by on patch 1/2.
- v2: https://lore.kernel.org/linux-nfs/20261124180606.73719-1-dmnk@google.com/
Found with an AI-assisted code review tool (ARTIST) and verified in
QEMU/KVM over NFSv4.1 across 0711, 0744, 0400, regular files, and stale
filehandles.
Dominik Maier (2):
nfsd: return GDD4_UNAVAIL on nfserr_acces in
nfsd4_get_dir_delegation()
nfsd: require NFSD_MAY_EXEC when acquiring directory delegations
fs/nfsd/filecache.c | 10 ++++++----
fs/nfsd/nfs4proc.c | 4 ++++
2 files changed, 10 insertions(+), 4 deletions(-)
base-commit: 6104bc60edc0d9c6bbc509ec9df4b8c26b1d31a3
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v3 1/2] nfsd: return GDD4_UNAVAIL on nfserr_acces in nfsd4_get_dir_delegation() 2026-11-30 16:04 [PATCH v3 0/2] nfsd: enforce search permission on directory delegations Dominik Maier @ 2026-11-30 16:04 ` Dominik Maier 2026-11-30 18:48 ` Chuck Lever 2026-11-30 16:04 ` [PATCH v3 2/2] nfsd: require NFSD_MAY_EXEC when acquiring directory delegations Dominik Maier 1 sibling, 1 reply; 5+ messages in thread From: Dominik Maier @ 2026-11-30 16:04 UTC (permalink / raw) To: Chuck Lever, Jeff Layton Cc: NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey, linux-nfs, dmnk+artist Failing a directory delegation request with access denied aborts the entire NFSv4 COMPOUND and breaks client stat() on search-only (mode 0711) directories. The Linux NFS client places GET_DIR_DELEGATION before GETATTR in one COMPOUND and does not expect NFS4ERR_ACCESS from the delegation step. Reply NFS4_OK with GDD4_UNAVAIL on nfserr_acces so the delegation is declined and the trailing GETATTR still runs, while returning other errors such as non-directory or stale filehandles directly. Fixes: 8b99f6a8c116 ("nfsd: wire up GET_DIR_DELEGATION handling") Cc: stable@vger.kernel.org Suggested-by: Chuck Lever <cel@kernel.org> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Dominik Maier <dmnk@google.com> --- fs/nfsd/nfs4proc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index bb149a3e9aa4..28e61832331d 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -2934,6 +2934,10 @@ nfsd4_get_dir_delegation(struct svc_rqst *rqstp, __be32 status; status = nfsd_file_acquire_dir(rqstp, &cstate->current_fh, &nf); + if (status == nfserr_acces) { + gdd->gddrnf_status = GDD4_UNAVAIL; + return nfs_ok; + } if (status != nfs_ok) return status; -- 2.56.1.911.g883d8bcb20-goog ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/2] nfsd: return GDD4_UNAVAIL on nfserr_acces in nfsd4_get_dir_delegation() 2026-11-30 16:04 ` [PATCH v3 1/2] nfsd: return GDD4_UNAVAIL on nfserr_acces in nfsd4_get_dir_delegation() Dominik Maier @ 2026-11-30 18:48 ` Chuck Lever 0 siblings, 0 replies; 5+ messages in thread From: Chuck Lever @ 2026-11-30 18:48 UTC (permalink / raw) To: Dominik Maier Cc: Jeff Layton, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey, linux-nfs, dmnk+artist On Mon, Nov 30, 2026, Dominik Maier wrote: > diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c > index 92a92b3e6da8..58d8faa67e31 100644 > --- a/fs/nfsd/nfs4proc.c > +++ b/fs/nfsd/nfs4proc.c > @@ -2934,6 +2934,10 @@ nfsd4_get_dir_delegation(struct svc_rqst *rqstp, > __be32 status; > > status = nfsd_file_acquire_dir(rqstp, &cstate->current_fh, &nf); > + if (status == nfserr_acces) { nfsd_file_acquire_dir() can fail here with nfserr_perm as well. When the open itself is refused, nfsd_file_do_acquire() passes the error from nfsd_open_verified() through nfserrno(). A fanotify FAN_OPEN_PERM listener that denies the open returns -EPERM by default, and an LSM file_open hook can return -EPERM as well. In both cases status is nfserr_perm. That status misses this check, so the COMPOUND still aborts before the GETATTR runs, and stat() fails as the commit message describes. Would it make sense to treat nfserr_perm the same way? > + gdd->gddrnf_status = GDD4_UNAVAIL; > + return nfs_ok; > + } Nit: this block duplicates the exit further down in nfsd4_get_dir_delegation(): dd = nfsd_get_dir_deleg(cstate, gdd, nf); nfsd_file_put(nf); if (IS_ERR(dd)) { gdd->gddrnf_status = GDD4_UNAVAIL; return nfs_ok; } The comment that explains why NFSD replies NFS4_OK with GDD4_UNAVAIL instead of NFS4ERR_DIRDELEG_UNAVAIL (RFC 8881 Section 18.39.3) sits only above the second copy. Let's have both sites jump to a shared out_unavail label, with the RFC comment moved there. -- Chuck Lever ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 2/2] nfsd: require NFSD_MAY_EXEC when acquiring directory delegations 2026-11-30 16:04 [PATCH v3 0/2] nfsd: enforce search permission on directory delegations Dominik Maier 2026-11-30 16:04 ` [PATCH v3 1/2] nfsd: return GDD4_UNAVAIL on nfserr_acces in nfsd4_get_dir_delegation() Dominik Maier @ 2026-11-30 16:04 ` Dominik Maier 2026-11-30 18:48 ` Chuck Lever 1 sibling, 1 reply; 5+ messages in thread From: Dominik Maier @ 2026-11-30 16:04 UTC (permalink / raw) To: Chuck Lever, Jeff Layton Cc: NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey, linux-nfs, dmnk+artist Clients can obtain a directory delegation without search permission and receive child filehandles in change notifications even when LOOKUP is denied. Opening a directory for delegation currently checks only read access and applies the file-owner permission override to directories as well, allowing delegations on mode 0744 directories for non-owners and mode 0400 directories for the owner. Require search permission when acquiring a directory for delegation and restrict the owner permission override to regular files, matching normal file opens. 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.911.g883d8bcb20-goog ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 2/2] nfsd: require NFSD_MAY_EXEC when acquiring directory delegations 2026-11-30 16:04 ` [PATCH v3 2/2] nfsd: require NFSD_MAY_EXEC when acquiring directory delegations Dominik Maier @ 2026-11-30 18:48 ` Chuck Lever 0 siblings, 0 replies; 5+ messages in thread From: Chuck Lever @ 2026-11-30 18:48 UTC (permalink / raw) To: Dominik Maier, Jeff Layton Cc: NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey, linux-nfs, dmnk+artist On Mon, Nov 30, 2026, at 11:04 AM, Dominik Maier wrote: > Clients can obtain a directory delegation without search permission and > receive child filehandles in change notifications even when LOOKUP is > denied. > > Opening a directory for delegation currently checks only read access and > applies the file-owner permission override to directories as well, > allowing delegations on mode 0744 directories for non-owners and mode > 0400 directories for the owner. > > Require search permission when acquiring a directory for delegation and > restrict the owner permission override to regular files, matching normal > file opens. > > 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> This patch appears to make the kernel-doc for nfsd_file_acquire_dir() stale. The comment still describes a generic helper that opens a directory read- only. The function now also requires search permission, a rule specific to directory delegations: READDIR opens with NFSD_MAY_READ only. I suggest adding one sentence, for example: "The caller must have read and search permission on the directory, because a directory delegation exposes the names and filehandles of its entries." -- Chuck Lever ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-30 18:49 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-30 16:04 [PATCH v3 0/2] nfsd: enforce search permission on directory delegations Dominik Maier 2026-11-30 16:04 ` [PATCH v3 1/2] nfsd: return GDD4_UNAVAIL on nfserr_acces in nfsd4_get_dir_delegation() Dominik Maier 2026-11-30 18:48 ` Chuck Lever 2026-11-30 16:04 ` [PATCH v3 2/2] nfsd: require NFSD_MAY_EXEC when acquiring directory delegations Dominik Maier 2026-11-30 18:48 ` Chuck Lever
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox