Skip to content

Commit de5dac2

Browse files
neilbrowngregkh
authored andcommitted
nfs/localio: must clear res.replen in nfs_local_read_done
[ Upstream commit 650703b ] Otherwise memory corruption can occur due to NFSv3 LOCALIO reads leaving garbage in res.replen: - nfs3_read_done() copies that into server->read_hdrsize; from there nfs3_proc_read_setup() copies it to args.replen in new requests. - nfs3_xdr_enc_read3args() passes that to rpc_prepare_reply_pages() which includes it in hdrsize for xdr_init_pages, so that rq_rcv_buf contains a ridiculous len. - This is copied to rq_private_buf and xs_read_stream_request() eventually passes the kvec to sock_recvmsg() which receives incoming data into entirely the wrong place. This is easily reproduced with NFSv3 LOCALIO that is servicing reads when it is made to pivot back to using normal RPC. This switch back to using normal NFSv3 with RPC can occur for a few reasons but this issue was exposed with a test that stops and then restarts the NFSv3 server while LOCALIO is performing heavy read IO. Fixes: 70ba381 ("nfs: add LOCALIO support") Reported-by: Mike Snitzer <snitzer@kernel.org> Signed-off-by: NeilBrown <neilb@suse.de> Co-developed-by: Mike Snitzer <snitzer@kernel.org> Signed-off-by: Mike Snitzer <snitzer@kernel.org> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent b56ae8e commit de5dac2

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

fs/nfs/localio.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,12 @@ nfs_local_read_done(struct nfs_local_kiocb *iocb, long status)
354354

355355
nfs_local_pgio_done(hdr, status);
356356

357+
/*
358+
* Must clear replen otherwise NFSv3 data corruption will occur
359+
* if/when switching from LOCALIO back to using normal RPC.
360+
*/
361+
hdr->res.replen = 0;
362+
357363
if (hdr->res.count != hdr->args.count ||
358364
hdr->args.offset + hdr->res.count >= i_size_read(file_inode(filp)))
359365
hdr->res.eof = true;

0 commit comments

Comments
 (0)