Skip to content

Commit 38b7631

Browse files
bcodding-rhtrondmypd
authored andcommitted
nfs4: limit callback decoding to received bytes
A truncated cb_compound request will cause the client to decode null or data from a previous callback for nfs4.1 backchannel case, or uninitialized data for the nfs4.0 case. This is because the path through svc_process_common() advances the request's iov_base and decrements iov_len without adjusting the overall xdr_buf's len field. That causes xdr_init_decode() to set up the xdr_stream with an incorrect length in nfs4_callback_compound(). Fixing this for the nfs4.1 backchannel case first requires setting the correct iov_len and page_len based on the length of received data in the same manner as the nfs4.0 case. Then the request's xdr_buf length can be adjusted for both cases based upon the remaining iov_len and page_len. Signed-off-by: Benjamin Coddington <bcodding@redhat.com> Cc: stable@vger.kernel.org Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
1 parent c68a027 commit 38b7631

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

fs/nfs/callback_xdr.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ static __be32 *read_buf(struct xdr_stream *xdr, int nbytes)
7878

7979
p = xdr_inline_decode(xdr, nbytes);
8080
if (unlikely(p == NULL))
81-
printk(KERN_WARNING "NFS: NFSv4 callback reply buffer overflowed!\n");
81+
printk(KERN_WARNING "NFS: NFSv4 callback reply buffer overflowed "
82+
"or truncated request.\n");
8283
return p;
8384
}
8485

@@ -889,6 +890,7 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *r
889890
struct cb_compound_hdr_arg hdr_arg = { 0 };
890891
struct cb_compound_hdr_res hdr_res = { NULL };
891892
struct xdr_stream xdr_in, xdr_out;
893+
struct xdr_buf *rq_arg = &rqstp->rq_arg;
892894
__be32 *p, status;
893895
struct cb_process_state cps = {
894896
.drc_status = 0,
@@ -900,7 +902,8 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *r
900902

901903
dprintk("%s: start\n", __func__);
902904

903-
xdr_init_decode(&xdr_in, &rqstp->rq_arg, rqstp->rq_arg.head[0].iov_base);
905+
rq_arg->len = rq_arg->head[0].iov_len + rq_arg->page_len;
906+
xdr_init_decode(&xdr_in, rq_arg, rq_arg->head[0].iov_base);
904907

905908
p = (__be32*)((char *)rqstp->rq_res.head[0].iov_base + rqstp->rq_res.head[0].iov_len);
906909
xdr_init_encode(&xdr_out, &rqstp->rq_res, p);

net/sunrpc/backchannel_rqst.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,20 @@ void xprt_complete_bc_request(struct rpc_rqst *req, uint32_t copied)
353353
{
354354
struct rpc_xprt *xprt = req->rq_xprt;
355355
struct svc_serv *bc_serv = xprt->bc_serv;
356+
struct xdr_buf *rq_rcv_buf = &req->rq_rcv_buf;
356357

357358
spin_lock(&xprt->bc_pa_lock);
358359
list_del(&req->rq_bc_pa_list);
359360
xprt_dec_alloc_count(xprt, 1);
360361
spin_unlock(&xprt->bc_pa_lock);
361362

363+
if (copied <= rq_rcv_buf->head[0].iov_len) {
364+
rq_rcv_buf->head[0].iov_len = copied;
365+
rq_rcv_buf->page_len = 0;
366+
} else {
367+
rq_rcv_buf->page_len = copied - rq_rcv_buf->head[0].iov_len;
368+
}
369+
362370
req->rq_private_buf.len = copied;
363371
set_bit(RPC_BC_PA_IN_USE, &req->rq_bc_pa_state);
364372

net/sunrpc/svc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,7 @@ bc_svc_process(struct svc_serv *serv, struct rpc_rqst *req,
13631363
memcpy(&rqstp->rq_addr, &req->rq_xprt->addr, rqstp->rq_addrlen);
13641364
memcpy(&rqstp->rq_arg, &req->rq_rcv_buf, sizeof(rqstp->rq_arg));
13651365
memcpy(&rqstp->rq_res, &req->rq_snd_buf, sizeof(rqstp->rq_res));
1366+
rqstp->rq_arg.len = req->rq_private_buf.len;
13661367

13671368
/* reset result send buffer "put" position */
13681369
resv->iov_len = 0;

0 commit comments

Comments
 (0)