SUNRPC: Fix svcxdr_init_encode's buflen calculation
authorChuck Lever <chuck.lever@oracle.com>
Thu, 1 Sep 2022 19:09:59 +0000 (15:09 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Oct 2022 10:34:38 +0000 (12:34 +0200)
commitcedaf73c8bdaa666cd125257861155f273464a6f
tree01568bd78e29030cc312c4eedc03184c9cd4f66e
parent6b55707ff8b296243a9cf6636d6d8459b6a4a7f8
SUNRPC: Fix svcxdr_init_encode's buflen calculation

[ Upstream commit 1242a87da0d8cd2a428e96ca68e7ea899b0f4624 ]

Commit 2825a7f90753 ("nfsd4: allow encoding across page boundaries")
added an explicit computation of the remaining length in the rq_res
XDR buffer.

The computation appears to suffer from an "off-by-one" bug. Because
buflen is too large by one page, XDR encoding can run off the end of
the send buffer by eventually trying to use the struct page address
in rq_page_end, which always contains NULL.

Fixes: bddfdbcddbe2 ("NFSD: Extract the svcxdr_init_encode() helper")
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/sunrpc/svc.h