* [PATCH 6.12.y 1/2] nfsd: fix file change detection in CB_GETATTR
@ 2026-07-02 20:27 Chuck Lever
2026-07-02 20:27 ` [PATCH 6.12.y 2/2] nfsd: release layout stid on setlease failure Chuck Lever
2026-07-04 2:05 ` [PATCH 6.12.y 1/2] nfsd: fix file change detection in CB_GETATTR Sasha Levin
0 siblings, 2 replies; 4+ messages in thread
From: Chuck Lever @ 2026-07-02 20:27 UTC (permalink / raw)
To: stable; +Cc: linux-nfs, Scott Mayhew
From: Scott Mayhew <smayhew@redhat.com>
commit 304d81a2fbf2b454def4debcb38ea173911b72cd upstream.
RFC 8881, section 10.4.3 doesn't say anything about caching the file
size in the delegation record, nor does it say anything about comparing
a cached file size with the size reported by the client in the
CB_GETATTR reply for the purpose of determining if the client holds
modified data for the file.
What section 10.4.3 of RFC 8881 does say is that the server should
compare the *current* file size with the size reported by the client
holding the delegation in the CB_GETATTR reply, and if they differ to
treat it as a modification regardless of the change attribute retrieved
via the CB_GETATTR.
Doing otherwise would cause the server to believe the client holding the
delegation has a modified version of the file, even if the client
flushed the modifications to the server prior to the CB_GETATTR. This
would have the added side effect of subsequent CB_GETATTRs causing
updates to the mtime, ctime, and change attribute even if the client
holding the delegation makes no further updates to the file.
Modify nfsd4_deleg_getattr_conflict() to obtain the current file size
via i_size_read(). Retain the ncf_cur_fsize field, since it's a
convenient way to return the file size back to nfsd4_encode_fattr4(),
but don't use it for the purpose of detecting file changes. Remove the
unnecessary initialization of ncf_cur_fsize in nfs4_open_delegation().
Also, if we recall the delegation (because the client didn't respond to
the CB_GETATTR), then skip the logic that checks the nfs4_cb_fattr
fields.
Fixes: c5967721e106 ("NFSD: handle GETATTR conflict with write delegation")
Cc: stable@vger.kernel.org
Signed-off-by: Scott Mayhew <smayhew@redhat.com>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
[ cel: no deleg_ts in 6.12.y; dropped the now-dead ncf_cur_fsize init ]
Signed-off-by: Chuck Lever <cel@kernel.org>
---
fs/nfsd/nfs4state.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 2d9174729782..33102bc65b7c 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -6085,7 +6085,6 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp,
goto out_no_deleg;
}
open->op_delegate_type = NFS4_OPEN_DELEGATE_WRITE;
- dp->dl_cb_fattr.ncf_cur_fsize = stat.size;
dp->dl_cb_fattr.ncf_initial_cinfo = nfsd4_change_attribute(&stat);
trace_nfsd_deleg_write(&dp->dl_stid.sc_stateid);
} else {
@@ -9039,11 +9038,15 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry,
if (status != nfserr_jukebox ||
!nfsd_wait_for_delegreturn(rqstp, inode))
goto out_status;
+ status = nfs_ok;
+ goto out_status;
+ }
+ if (!ncf->ncf_file_modified) {
+ if (ncf->ncf_initial_cinfo != ncf->ncf_cb_change)
+ ncf->ncf_file_modified = true;
+ else if (i_size_read(inode) != ncf->ncf_cb_fsize)
+ ncf->ncf_file_modified = true;
}
- if (!ncf->ncf_file_modified &&
- (ncf->ncf_initial_cinfo != ncf->ncf_cb_change ||
- ncf->ncf_cur_fsize != ncf->ncf_cb_fsize))
- ncf->ncf_file_modified = true;
if (ncf->ncf_file_modified) {
int err;
--
2.54.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 6.12.y 2/2] nfsd: release layout stid on setlease failure
2026-07-02 20:27 [PATCH 6.12.y 1/2] nfsd: fix file change detection in CB_GETATTR Chuck Lever
@ 2026-07-02 20:27 ` Chuck Lever
2026-07-02 20:45 ` Chuck Lever
2026-07-04 2:05 ` [PATCH 6.12.y 1/2] nfsd: fix file change detection in CB_GETATTR Sasha Levin
1 sibling, 1 reply; 4+ messages in thread
From: Chuck Lever @ 2026-07-02 20:27 UTC (permalink / raw)
To: stable; +Cc: linux-nfs, Jeff Layton
commit 30d55c8aabb261bc3f427d6b9aae7ef6206063f9 upstream.
nfs4_alloc_stid() publishes the new stid into cl->cl_stateids via
idr_alloc_cyclic() under cl_lock before returning to
nfsd4_alloc_layout_stateid(). When nfsd4_layout_setlease() then
fails, the error path frees the layout stateid directly with
kmem_cache_free() without ever calling idr_remove(), leaving the
IDR slot pointing at freed slab memory. Any subsequent IDR walker
(states_show, client teardown) dereferences the dangling pointer.
The correct teardown for an IDR-published stid is nfs4_put_stid(),
which removes the IDR slot under cl_lock, dispatches sc_free
(nfsd4_free_layout_stateid) to release ls->ls_file via
nfsd4_close_layout(), and drops the nfs4_file reference in its
tail.
Replace the manual nfsd_file_put + put_nfs4_file + kmem_cache_free
cleanup with a single nfs4_put_stid(stp).
Fixes: c5c707f96fc9 ("nfsd: implement pNFS layout recalls")
Cc: stable@vger.kernel.org
Signed-off-by: Chris Mason <clm@meta.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Chuck Lever <cel@kernel.org>
[ cel: no ls_fence_work in 6.12.y; dropped INIT_DELAYED_WORK hunk ]
Signed-off-by: Chuck Lever <cel@kernel.org>
---
fs/nfsd/nfs4layouts.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/fs/nfsd/nfs4layouts.c b/fs/nfsd/nfs4layouts.c
index fc5e82eddaa1..c08bc2d0d377 100644
--- a/fs/nfsd/nfs4layouts.c
+++ b/fs/nfsd/nfs4layouts.c
@@ -256,9 +256,7 @@ nfsd4_alloc_layout_stateid(struct nfsd4_compound_state *cstate,
BUG_ON(!ls->ls_file);
if (nfsd4_layout_setlease(ls)) {
- nfsd_file_put(ls->ls_file);
- put_nfs4_file(fp);
- kmem_cache_free(nfs4_layout_stateid_cache, ls);
+ nfs4_put_stid(stp);
return NULL;
}
--
2.54.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 6.12.y 2/2] nfsd: release layout stid on setlease failure
2026-07-02 20:27 ` [PATCH 6.12.y 2/2] nfsd: release layout stid on setlease failure Chuck Lever
@ 2026-07-02 20:45 ` Chuck Lever
0 siblings, 0 replies; 4+ messages in thread
From: Chuck Lever @ 2026-07-02 20:45 UTC (permalink / raw)
To: stable; +Cc: linux-nfs, Jeff Layton
Please note: The correct Author for this patch is "Chris Mason <clm@meta.com>"
On Thu, Jul 2, 2026, at 4:27 PM, Chuck Lever wrote:
> commit 30d55c8aabb261bc3f427d6b9aae7ef6206063f9 upstream.
>
> nfs4_alloc_stid() publishes the new stid into cl->cl_stateids via
> idr_alloc_cyclic() under cl_lock before returning to
> nfsd4_alloc_layout_stateid(). When nfsd4_layout_setlease() then
> fails, the error path frees the layout stateid directly with
> kmem_cache_free() without ever calling idr_remove(), leaving the
> IDR slot pointing at freed slab memory. Any subsequent IDR walker
> (states_show, client teardown) dereferences the dangling pointer.
>
> The correct teardown for an IDR-published stid is nfs4_put_stid(),
> which removes the IDR slot under cl_lock, dispatches sc_free
> (nfsd4_free_layout_stateid) to release ls->ls_file via
> nfsd4_close_layout(), and drops the nfs4_file reference in its
> tail.
>
> Replace the manual nfsd_file_put + put_nfs4_file + kmem_cache_free
> cleanup with a single nfs4_put_stid(stp).
>
> Fixes: c5c707f96fc9 ("nfsd: implement pNFS layout recalls")
> Cc: stable@vger.kernel.org
> Signed-off-by: Chris Mason <clm@meta.com>
> Reviewed-by: Jeff Layton <jlayton@kernel.org>
> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
> Signed-off-by: Chuck Lever <cel@kernel.org>
> [ cel: no ls_fence_work in 6.12.y; dropped INIT_DELAYED_WORK hunk ]
> Signed-off-by: Chuck Lever <cel@kernel.org>
> ---
> fs/nfsd/nfs4layouts.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/fs/nfsd/nfs4layouts.c b/fs/nfsd/nfs4layouts.c
> index fc5e82eddaa1..c08bc2d0d377 100644
> --- a/fs/nfsd/nfs4layouts.c
> +++ b/fs/nfsd/nfs4layouts.c
> @@ -256,9 +256,7 @@ nfsd4_alloc_layout_stateid(struct
> nfsd4_compound_state *cstate,
> BUG_ON(!ls->ls_file);
>
> if (nfsd4_layout_setlease(ls)) {
> - nfsd_file_put(ls->ls_file);
> - put_nfs4_file(fp);
> - kmem_cache_free(nfs4_layout_stateid_cache, ls);
> + nfs4_put_stid(stp);
> return NULL;
> }
>
> --
> 2.54.0
--
Chuck Lever
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 6.12.y 1/2] nfsd: fix file change detection in CB_GETATTR
2026-07-02 20:27 [PATCH 6.12.y 1/2] nfsd: fix file change detection in CB_GETATTR Chuck Lever
2026-07-02 20:27 ` [PATCH 6.12.y 2/2] nfsd: release layout stid on setlease failure Chuck Lever
@ 2026-07-04 2:05 ` Sasha Levin
1 sibling, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2026-07-04 2:05 UTC (permalink / raw)
To: stable; +Cc: Sasha Levin, linux-nfs, Scott Mayhew, Chuck Lever
On Thu, Jul 02, 2026 at 04:27:48PM -0400, Chuck Lever wrote:
> commit 304d81a2fbf2b454def4debcb38ea173911b72cd upstream.
Queued the series for 6.12.y, with the author of 2/2 fixed up to Chris
Mason per your follow-up. Thanks!
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-04 2:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-02 20:27 [PATCH 6.12.y 1/2] nfsd: fix file change detection in CB_GETATTR Chuck Lever
2026-07-02 20:27 ` [PATCH 6.12.y 2/2] nfsd: release layout stid on setlease failure Chuck Lever
2026-07-02 20:45 ` Chuck Lever
2026-07-04 2:05 ` [PATCH 6.12.y 1/2] nfsd: fix file change detection in CB_GETATTR Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox