Skip to content

Commit ccd608e

Browse files
committed
NFSD: Add array bounds-checking in nfsd_iter_read()
The *count parameter does not appear to be explicitly restricted to being smaller than rsize, so it might be possible to overrun the rq_bvec or rq_pages arrays. Rather than overrunning these arrays (damage done!) and then WARNING once, let's harden the loop so that it terminates before the end of the arrays are reached. This should result in a short read, which is OK -- clients recover by sending additional READ requests for the remaining unread bytes. Reported-by: NeilBrown <neil@brown.name> Reviewed-by: Jeff Layton <jlayton@kernel.org> Reviewed-by: Mike Snitzer <snitzer@kernel.org> Reviewed-by: NeilBrown <neil@brown.name> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent b5fc406 commit ccd608e

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

fs/nfsd/vfs.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,18 +1115,20 @@ __be32 nfsd_iter_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
11151115

11161116
v = 0;
11171117
total = *count;
1118-
while (total) {
1118+
while (total && v < rqstp->rq_maxpages &&
1119+
rqstp->rq_next_page < rqstp->rq_page_end) {
11191120
len = min_t(size_t, total, PAGE_SIZE - base);
1120-
bvec_set_page(&rqstp->rq_bvec[v], *(rqstp->rq_next_page++),
1121+
bvec_set_page(&rqstp->rq_bvec[v], *rqstp->rq_next_page,
11211122
len, base);
1123+
11221124
total -= len;
1125+
++rqstp->rq_next_page;
11231126
++v;
11241127
base = 0;
11251128
}
1126-
WARN_ON_ONCE(v > rqstp->rq_maxpages);
11271129

1128-
trace_nfsd_read_vector(rqstp, fhp, offset, *count);
1129-
iov_iter_bvec(&iter, ITER_DEST, rqstp->rq_bvec, v, *count);
1130+
trace_nfsd_read_vector(rqstp, fhp, offset, *count - total);
1131+
iov_iter_bvec(&iter, ITER_DEST, rqstp->rq_bvec, v, *count - total);
11301132
host_err = vfs_iocb_iter_read(file, &kiocb, &iter);
11311133
return nfsd_finish_read(rqstp, fhp, file, offset, count, eof, host_err);
11321134
}

0 commit comments

Comments
 (0)