* [PATCH] SUNRPC: copy the GSS init token with read_bytes_from_xdr_buf()
@ 2026-11-20 6:00 Yiran Qiu
0 siblings, 0 replies; only message in thread
From: Yiran Qiu @ 2026-11-20 6:00 UTC (permalink / raw)
To: cel, jlayton
Cc: neil, okorniev, Dai.Ngo, tom, linux-nfs, linux-kernel, Yiran Qiu, stable
gss_read_proxy_verf() copies the token from the head of rq_arg and then
from rq_arg.pages, assuming the rest of the token is in the page list.
svcrdma rebuilds a Call that carries one Read chunk as head (inline data
before the chunk position), pages (the chunk) and tail (inline data
after it), and xdr_stream_remaining() counts the tail. When the token
starts at the chunk and continues into the tail, the copy runs past the
chunk's pages. If the chunk fills rq_pages, the copy takes the NULL
entry at rq_pages[rq_maxpages] and memcpy() reads from
page_address(NULL); otherwise the stale contents of the next page go to
gssproxy in place of the tail. This runs in svcauth_gss_proxy_init()
before any credential is checked, so a client of an NFS/RDMA server that
uses gssproxy can oops nfsd threads without authenticating.
Commit 62319c2534b6 ("SUNRPC: fix oversized GSS proxy token copy") fixed
the copy from the head and left the copy from the pages as it was. Copy
the token with read_bytes_from_xdr_buf(), which follows head, pages and
tail.
Found with afb-afl, an LLM-driven kernel audit/repro pipeline; the fix
and this changelog were also drafted with LLM assistance. Reproduced on
an unmodified KASAN build of mainline, nfsd listening on "rdma 20049"
over rxe with use-gss-proxy set. An RPCSEC_GSS INIT Call whose token is
a 12-page Read chunk (max_block_size 32768) plus 64 inline bytes gives
(gss_read_proxy_verf() is inlined):
BUG: KASAN: wild-memory-access in svcauth_gss_proxy_init+0x71f/0xe10
Read of size 64 at addr 0005088000000000 by task nfsd/184
__asan_memcpy+0x23/0x60
svcauth_gss_proxy_init+0x71f/0xe10
svcauth_gss_proc_init+0x22b/0x440
With an 11-page chunk, gssproxy received the chunk followed by 64 bytes
that were not the tail. With this patch there is no report and gssproxy
receives the chunk followed by the tail, for 12- and 11-page chunks; a
chunk without a tail and an inline token are unchanged. Over TCP, tokens
of 100 to 30000 bytes reach gssproxy intact with and without this patch.
Kerberos and NFS functional tests were not run.
Fixes: 5866efa8cbfb ("SUNRPC: Fix svcauth_gss_proxy_init()")
Cc: stable@vger.kernel.org
Signed-off-by: Yiran Qiu <eritque-arcus@ikuyo.dev>
---
Tested on mainline 4405c18c95d2 (v7.4-rc3+) in QEMU. Applies to
cel/linux.git nfsd-next and nfsd-testing.
A reproducer and the test logs are available on request.
net/sunrpc/auth_gss/svcauth_gss.c | 38 +++++++++----------------------
1 file changed, 11 insertions(+), 27 deletions(-)
diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
index 43839e805531..da4043aed247 100644
--- a/net/sunrpc/auth_gss/svcauth_gss.c
+++ b/net/sunrpc/auth_gss/svcauth_gss.c
@@ -1056,9 +1056,8 @@ static int gss_read_proxy_verf(struct svc_rqst *rqstp,
struct gssp_in_token *in_token)
{
struct xdr_stream *xdr = &rqstp->rq_arg_stream;
- unsigned int length, pgto_offs, pgfrom_offs;
- int pages, i, pgto, pgfrom;
- size_t to_offs, from_offs;
+ unsigned int base, length;
+ int pages, i;
u32 inlen;
if (dup_netobj(in_handle, &gc->gc_ctx))
@@ -1090,30 +1089,15 @@ static int gss_read_proxy_verf(struct svc_rqst *rqstp,
}
}
- length = min_t(unsigned int, inlen, (char *)xdr->end - (char *)xdr->p);
- for (to_offs = 0; to_offs < length; to_offs += PAGE_SIZE)
- memcpy(page_address(in_token->pages[to_offs >> PAGE_SHIFT]),
- (char *)xdr->p + to_offs,
- min_t(unsigned int, length - to_offs, PAGE_SIZE));
- inlen -= length;
- to_offs = length;
- from_offs = rqstp->rq_arg.page_base;
- while (inlen) {
- pgto = to_offs >> PAGE_SHIFT;
- pgfrom = from_offs >> PAGE_SHIFT;
- pgto_offs = to_offs & ~PAGE_MASK;
- pgfrom_offs = from_offs & ~PAGE_MASK;
-
- length = min_t(unsigned int, inlen,
- min_t(unsigned int, PAGE_SIZE - pgto_offs,
- PAGE_SIZE - pgfrom_offs));
- memcpy(page_address(in_token->pages[pgto]) + pgto_offs,
- page_address(rqstp->rq_arg.pages[pgfrom]) + pgfrom_offs,
- length);
-
- to_offs += length;
- from_offs += length;
- inlen -= length;
+ base = xdr_stream_pos(xdr);
+ for (i = 0; i < pages; i++) {
+ length = min_t(unsigned int, inlen - i * PAGE_SIZE, PAGE_SIZE);
+ if (read_bytes_from_xdr_buf(&rqstp->rq_arg, base + i * PAGE_SIZE,
+ page_address(in_token->pages[i]),
+ length)) {
+ gss_free_in_token_pages(in_token);
+ goto out_denied_free;
+ }
}
return 0;
--
2.56.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-20 6:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 6:00 [PATCH] SUNRPC: copy the GSS init token with read_bytes_from_xdr_buf() Yiran Qiu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®