All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xiaobo Liu <cppcoffee@gmail.com>
To: Chuck Lever <chuck.lever@oracle.com>, Jeff Layton <jlayton@kernel.org>
Cc: NeilBrown <neil@brown.name>,
	Olga Kornievskaia <okorniev@redhat.com>,
	Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
	linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	Xiaobo Liu <cppcoffee@gmail.com>
Subject: [PATCH] nfsd: fix replay buffer length underflow in nfsd4_encode_operation
Date: Sun, 12 Apr 2026 21:01:33 +0800	[thread overview]
Message-ID: <20260412130133.2308-1-cppcoffee@gmail.com> (raw)

When nfsd4_encode_operation() truncates the reply back to
op_status_offset + XDR_UNIT, the replay-cache path may still try to
compute the encoded payload length from xdr->buf->len.

If xdr->buf->len is smaller than op_status_offset + XDR_UNIT, the
subtraction underflows and the result is assigned to an int. That can
produce an invalid negative/small value, allowing the subsequent
NFSD4_REPLAY_ISIZE check to make the wrong decision and use a bogus
length for replay-buffer handling.

Fix this by validating the buffer length before subtracting. If the
encoded length would underflow, force the value into the "too large to
cache" path so rp_buflen is cleared instead of reading invalid data.

Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
---
 fs/nfsd/nfs4xdr.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 9d2349131..5e9e49057 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -6278,9 +6278,14 @@ nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op)
 		warn_on_nonidempotent_op(op);
 		xdr_truncate_encode(xdr, op_status_offset + XDR_UNIT);
 	} else if (so) {
-		int len = xdr->buf->len - (op_status_offset + XDR_UNIT);
+		unsigned int len;
 
 		so->so_replay.rp_status = op->status;
+		if (xdr->buf->len >= op_status_offset + XDR_UNIT) {
+			len = xdr->buf->len - (op_status_offset + XDR_UNIT);
+		} else {
+			len = NFSD4_REPLAY_ISIZE + 1;
+		}
 		if (len <= NFSD4_REPLAY_ISIZE) {
 			so->so_replay.rp_buflen = len;
 			read_bytes_from_xdr_buf(xdr->buf,
-- 
2.34.1


             reply	other threads:[~2026-04-12 13:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-12 13:01 Xiaobo Liu [this message]
2026-04-13 18:21 ` [PATCH] nfsd: fix replay buffer length underflow in nfsd4_encode_operation Chuck Lever

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260412130133.2308-1-cppcoffee@gmail.com \
    --to=cppcoffee@gmail.com \
    --cc=Dai.Ngo@oracle.com \
    --cc=chuck.lever@oracle.com \
    --cc=jlayton@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neil@brown.name \
    --cc=okorniev@redhat.com \
    --cc=tom@talpey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.