Skip to contentSkip to conversation

SUNRPC: in svcauth_gss_wrap_integ() resync rq_next_page after the GSS wrap

PATCH In review Abhinandan Ekande 2 participants 2 messages Sep 22

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

PATCH 1/1 SUNRPC: in svcauth_gss_wrap_integ() resync rq_next_page after the GSS wrap

For a page-aligned READ payload, xdr_reserve_space_vec() leaves the encode cursor with p == end and page_ptr still on the last payload page. nfsd4_encode_operation() then resyncs rqstp->rq_next_page = xdr->page_ptr + 1, so rq_next_page points at the first page past the payload.

The GSS MIC is encoded later, after the last operation, and nothing resyncs rq_next_page after that. Because p == end, the MIC's xdr_reserve_space() falls into xdr_get_next_encode_buffer(), which increments page_ptr into the next page — the page rq_next_page points at. After the send, svc_rqst_release_pages() releases only 'rq_next_page - rq_respages' pages, so that page sits one past the release range and is never released. The next reply from the same nfsd thread writes its MIC into the same physical page while TCP still holds a MSG_SPLICE_PAGES reference to the previous reply, so that reply is transmitted carrying the wrong MIC.

mmap + fscache workloads hit this consistently because their READ payloads end exactly on a page boundary.

Before the commit 'd7de37d6d7cc', xdr_truncate_encode() ran after the reserve. For the page-aligned case xdr_truncate_encode() correctly recomputed page_ptr to point at the page after the payload. Therefore the later MIC encode had room and never crossed page boundary. That protection was a side effect rather than by design. The underlying hazard of MIC page falling outside the release range existed before the commit as well; for example payload that ends with fewer than a MIC's width of room left before the page boundary. The commit did not introduce the bug, it widened the trigger from that rare case to the page-aligned one.

The fix for this issue is to make the MIC page always fall inside the release range regardless of payload alignment - that is resync rq_next_page after the GSS wrap, for example, rqstp->rq_next_page = xdr->page_ptr + 1; at the end of svcauth_gss_wrap_integ().

Fixes d7de37d6d7cc ("NFSD: Relocate the xdr_reserve_space_vec() call site")
---
 net/sunrpc/auth_gss/svcauth_gss.c | 3 +++
 1 file changed, 3 insertions(+)
net/sunrpc/auth_gss/svcauth_gss.c +3 -0
index 967e9d53080d..06d75f98e954 100644
@@ -1820,6 +1820,9 @@ static int svcauth_gss_wrap_integ(struct svc_rqst *rqstp)
 		goto wrap_failed;
 	xdr_commit_encode(xdr);
 
+	if (xdr->page_ptr + 1 > rqstp->rq_next_page)
+		rqstp->rq_next_page = xdr->page_ptr + 1;
+
 out:
 	return 0;
 
Signature · 1 line
2.55.0
maintainer
#1 lore raw
Quoted 15 lines · Abhinandan Ekande

For a page-aligned READ payload, xdr_reserve_space_vec() leaves the encode cursor with p == end and page_ptr still on the last payload page. nfsd4_encode_operation() then resyncs rqstp->rq_next_page = xdr->page_ptr + 1, so rq_next_page points at the first page past the payload.

The GSS MIC is encoded later, after the last operation, and nothing resyncs rq_next_page after that. Because p == end, the MIC's xdr_reserve_space() falls into xdr_get_next_encode_buffer(), which increments page_ptr into the next page — the page rq_next_page points at. After the send, svc_rqst_release_pages() releases only 'rq_next_page - rq_respages' pages, so that page sits one past the release range and is never released. The next reply from the same nfsd thread writes its MIC into the same physical page while TCP still holds a MSG_SPLICE_PAGES reference to the previous reply, so that reply is transmitted carrying the wrong MIC.

Quoted 1 line

[...]

Applied to nfsd-testing, thanks!

[1/1] SUNRPC: in svcauth_gss_wrap_integ() resync rq_next_page after the GSS wrap

      commit: 1f04f4ab88bd62ea98bdf6490b385b6d046aafab

--
Chuck Lever