Skip to content

Commit

Permalink
NFSD: Fix "start of NFS reply" pointer passed to nfsd_cache_update()
Browse files Browse the repository at this point in the history
[ Upstream commit 1caf5f6 ]

The "statp + 1" pointer that is passed to nfsd_cache_update() is
supposed to point to the start of the egress NFS Reply header. In
fact, it does point there for AUTH_SYS and RPCSEC_GSS_KRB5 requests.

But both krb5i and krb5p add fields between the RPC header's
accept_stat field and the start of the NFS Reply header. In those
cases, "statp + 1" points at the extra fields instead of the Reply.
The result is that nfsd_cache_update() caches what looks to the
client like garbage.

A connection break can occur for a number of reasons, but the most
common reason when using krb5i/p is a GSS sequence number window
underrun. When an underrun is detected, the server is obliged to
drop the RPC and the connection to force a retransmit with a fresh
GSS sequence number. The client presents the same XID, it hits in
the server's DRC, and the server returns the garbage cache entry.

The "statp + 1" argument has been used since the oldest changeset
in the kernel history repo, so it has been in nfsd_dispatch()
literally since before history began. The problem arose only when
the server-side GSS implementation was added twenty years ago.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Tested-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
chucklever authored and gregkh committed Dec 3, 2023
1 parent d7eb376 commit b597f3c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion fs/nfsd/nfssvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,7 @@ nfsd(void *vrqstp)
int nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp)
{
const struct svc_procedure *proc = rqstp->rq_procinfo;
__be32 *nfs_reply;

/*
* Give the xdr decoder a chance to change this if it wants
Expand All @@ -1053,14 +1054,15 @@ int nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp)
*/
svcxdr_init_encode(rqstp);

nfs_reply = xdr_inline_decode(&rqstp->rq_res_stream, 0);
*statp = proc->pc_func(rqstp);
if (*statp == rpc_drop_reply || test_bit(RQ_DROPME, &rqstp->rq_flags))
goto out_update_drop;

if (!proc->pc_encode(rqstp, &rqstp->rq_res_stream))
goto out_encode_err;

nfsd_cache_update(rqstp, rqstp->rq_cachetype, statp + 1);
nfsd_cache_update(rqstp, rqstp->rq_cachetype, nfs_reply);
out_cached_reply:
return 1;

Expand Down

0 comments on commit b597f3c

Please sign in to comment.