Skip to contentSkip to conversation

nfsd: fix READ payload landing one page ahead of the XDR accounting

PATCH New Dairui Zhang 1 participant 1 message Sep 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfsd: fix READ payload landing one page ahead of the XDR accounting

nfsd4_encode_readv() passes the in-page offset
base = page_len & ~PAGE_MASK to nfsd_iter_read(), which writes the file data at that offset into *rq_next_page. After each operation rq_next_page is set to page_ptr + 1, so when the reply stream is mid-page the data lands one page ahead of where the payload accounting continues (which stays in the current page at base). The wire then carries the stale tail of the current page (previous RPC payloads, since reply pages are reallocated nonzeroed) instead of the file data: a remote kernel info leak to an authenticated client, plus silently corrupted READ results.

Trigger: any compound where a READ follows an op that left the stream mid-page, e.g. [PUTFH, READ(100), READ(N)] or READDIR+READ.

When base is nonzero, place the data in the page the accounting is filling (page_ptr) instead of one page ahead.

Fixes ed4a567a179e ("NFSD: Update rq_next_page between COMPOUND operations")
Assisted-by LLM

---

From code reading only - no runtime test yet; the trigger compound is in the commit message. First patch to this list, so if I've misread the flow somewhere, please tell me.

 fs/nfsd/nfs4xdr.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/nfsd/nfs4xdr.c +9 -0
index 6a0a97d..17aff48 100644
@@ -4933,6 +4933,15 @@ static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp,
 	__be32 zero = xdr_zero;
 	__be32 nfserr;
 
+	/*
+	 * rq_next_page only tracks full pages. When the reply stream is
+	 * mid-page, the payload accounting continues in the current page
+	 * at base, so the data must be placed there instead of one page
+	 * ahead.
+	 */
+	if (base)
+		resp->rqstp->rq_next_page = xdr->page_ptr;
+
 	nfserr = nfsd_iter_read(resp->rqstp, read->rd_fhp, read->rd_nf,
 				read->rd_offset, &maxcount, base,
 				&read->rd_eof);
Signature · 1 line
2.53.0