Skip to content

Commit

Permalink
NFSD: Update nfsd_cache_append() to use xdr_stream
Browse files Browse the repository at this point in the history
commit 49cecd8 upstream.

When inserting a DRC-cached response into the reply buffer, ensure
that the reply buffer's xdr_stream is updated properly. Otherwise
the server will send a garbage response.

Cc: stable@vger.kernel.org # v6.3+
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 Nov 28, 2023
1 parent 90ceb1e commit 4ce011e
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions fs/nfsd/nfscache.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,24 +582,17 @@ void nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
return;
}

/*
* Copy cached reply to current reply buffer. Should always fit.
* FIXME as reply is in a page, we should just attach the page, and
* keep a refcount....
*/
static int
nfsd_cache_append(struct svc_rqst *rqstp, struct kvec *data)
{
struct kvec *vec = &rqstp->rq_res.head[0];

if (vec->iov_len + data->iov_len > PAGE_SIZE) {
printk(KERN_WARNING "nfsd: cached reply too large (%zd).\n",
data->iov_len);
return 0;
}
memcpy((char*)vec->iov_base + vec->iov_len, data->iov_base, data->iov_len);
vec->iov_len += data->iov_len;
return 1;
__be32 *p;

p = xdr_reserve_space(&rqstp->rq_res_stream, data->iov_len);
if (unlikely(!p))
return false;
memcpy(p, data->iov_base, data->iov_len);
xdr_commit_encode(&rqstp->rq_res_stream);
return true;
}

/*
Expand Down

0 comments on commit 4ce011e

Please sign in to comment.