mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-09-22 09:34:56 +02:00
SUNRPC: Return an error from xdr_buf_to_bvec() on overflow
[ Upstream commit18c1cc6988] xdr_buf_to_bvec() returns a slot count even when the caller's bvec budget is exhausted partway through the xdr_buf. Callers feed that count into iov_iter_bvec() and continue as if the conversion had succeeded, silently sending or writing fewer bytes than the data length declares. For an NFS WRITE the server reports the truncated transfer to the client as full success. The overflow represents an internal invariant violation: a higher layer reserved a bvec budget too small for the xdr_buf it then asked the encoder to convert. That is a server-side fault, not a media I/O failure and not a malformed client argument. Change xdr_buf_to_bvec() to return a signed int and have the overflow label return -ESERVERFAULT. Update the three callers to detect the negative return and fail the request: nfsd_vfs_write() folds the error into host_err, which nfserrno() translates to nfserr_serverfault for the WRITE reply; svc_udp_sendto() and svc_tcp_sendmsg() propagate the error out of the send path. Reported-by: Chris Mason <clm@meta.com> Fixes:2eb2b93581("SUNRPC: Convert svc_tcp_sendmsg to use bio_vecs directly") Cc: stable@vger.kernel.org Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
18387968cf
commit
fc2214723b
@@ -139,8 +139,8 @@ void xdr_terminate_string(const struct xdr_buf *, const u32);
|
||||
size_t xdr_buf_pagecount(const struct xdr_buf *buf);
|
||||
int xdr_alloc_bvec(struct xdr_buf *buf, gfp_t gfp);
|
||||
void xdr_free_bvec(struct xdr_buf *buf);
|
||||
unsigned int xdr_buf_to_bvec(struct bio_vec *bvec, unsigned int bvec_size,
|
||||
const struct xdr_buf *xdr);
|
||||
int xdr_buf_to_bvec(struct bio_vec *bvec, unsigned int bvec_size,
|
||||
const struct xdr_buf *xdr);
|
||||
int xdr_buf_to_sg(const struct xdr_buf *buf, unsigned int offset,
|
||||
unsigned int len, struct scatterlist *sg, unsigned int nsg);
|
||||
int xdr_buf_to_sg_alloc(const struct xdr_buf *buf, unsigned int offset,
|
||||
|
||||
+12
-2
@@ -748,7 +748,7 @@ static int svc_udp_sendto(struct svc_rqst *rqstp)
|
||||
.msg_flags = MSG_SPLICE_PAGES,
|
||||
.msg_controllen = sizeof(buffer),
|
||||
};
|
||||
unsigned int count;
|
||||
int count;
|
||||
int err;
|
||||
|
||||
svc_udp_release_ctxt(xprt, rqstp->rq_xprt_ctxt);
|
||||
@@ -762,6 +762,10 @@ static int svc_udp_sendto(struct svc_rqst *rqstp)
|
||||
goto out_notconn;
|
||||
|
||||
count = xdr_buf_to_bvec(svsk->sk_bvec, SUNRPC_MAX_UDP_SENDPAGES, xdr);
|
||||
if (count < 0) {
|
||||
err = count;
|
||||
goto out_trace;
|
||||
}
|
||||
|
||||
iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, svsk->sk_bvec,
|
||||
count, rqstp->rq_res.len);
|
||||
@@ -773,6 +777,7 @@ static int svc_udp_sendto(struct svc_rqst *rqstp)
|
||||
err = sock_sendmsg(svsk->sk_sock, &msg);
|
||||
}
|
||||
|
||||
out_trace:
|
||||
trace_svcsock_udp_send(xprt, err);
|
||||
|
||||
mutex_unlock(&xprt->xpt_mutex);
|
||||
@@ -1260,7 +1265,7 @@ static int svc_tcp_sendmsg(struct svc_sock *svsk, struct svc_rqst *rqstp,
|
||||
struct msghdr msg = {
|
||||
.msg_flags = MSG_SPLICE_PAGES,
|
||||
};
|
||||
unsigned int count;
|
||||
int count;
|
||||
void *buf;
|
||||
int ret;
|
||||
|
||||
@@ -1278,10 +1283,15 @@ static int svc_tcp_sendmsg(struct svc_sock *svsk, struct svc_rqst *rqstp,
|
||||
|
||||
count = xdr_buf_to_bvec(svsk->sk_bvec + 1, RPCSVC_MAXPAGES,
|
||||
&rqstp->rq_res);
|
||||
if (count < 0) {
|
||||
ret = count;
|
||||
goto out;
|
||||
}
|
||||
|
||||
iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, svsk->sk_bvec,
|
||||
1 + count, sizeof(marker) + rqstp->rq_res.len);
|
||||
ret = sock_sendmsg(svsk->sk_sock, &msg);
|
||||
out:
|
||||
page_frag_free(buf);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
+6
-5
@@ -167,13 +167,14 @@ xdr_free_bvec(struct xdr_buf *buf)
|
||||
/**
|
||||
* xdr_buf_to_bvec - Copy components of an xdr_buf into a bio_vec array
|
||||
* @bvec: bio_vec array to populate
|
||||
* @bvec_size: element count of @bio_vec
|
||||
* @bvec_size: element count of @bvec
|
||||
* @xdr: xdr_buf to be copied
|
||||
*
|
||||
* Returns the number of entries consumed in @bvec.
|
||||
* Returns the number of entries consumed in @bvec on success, or
|
||||
* -ESERVERFAULT when @xdr does not fit within @bvec_size entries.
|
||||
*/
|
||||
unsigned int xdr_buf_to_bvec(struct bio_vec *bvec, unsigned int bvec_size,
|
||||
const struct xdr_buf *xdr)
|
||||
int xdr_buf_to_bvec(struct bio_vec *bvec, unsigned int bvec_size,
|
||||
const struct xdr_buf *xdr)
|
||||
{
|
||||
const struct kvec *head = xdr->head;
|
||||
const struct kvec *tail = xdr->tail;
|
||||
@@ -215,7 +216,7 @@ unsigned int xdr_buf_to_bvec(struct bio_vec *bvec, unsigned int bvec_size,
|
||||
|
||||
bvec_overflow:
|
||||
pr_warn_once("%s: bio_vec array overflow\n", __func__);
|
||||
return count;
|
||||
return -ESERVERFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user