From: Jeff Layton <jlayton@kernel.org>
To: Chuck Lever <cel@kernel.org>, NeilBrown <neilb@ownmail.net>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <dai.ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Cc: linux-nfs@vger.kernel.org, Chuck Lever <chuck.lever@oracle.com>
Subject: Re: [PATCH] SUNRPC: xdrgen: Initialize data pointer for zero-length items
Date: Mon, 22 Dec 2025 07:47:15 -0500 [thread overview]
Message-ID: <e8bbc54e23e1c38a1eb2d41a6550c3908f87a215.camel@kernel.org> (raw)
In-Reply-To: <20251220154109.1361512-1-cel@kernel.org>
On Sat, 2025-12-20 at 10:41 -0500, Chuck Lever wrote:
> From: Chuck Lever <chuck.lever@oracle.com>
>
> The xdrgen decoders for strings and opaque data had an
> optimization that skipped calling xdr_inline_decode() when the
> item length was zero. This left the data pointer uninitialized,
> which could lead to unpredictable behavior when callers access
> it.
>
> Remove the zero-length check and always call xdr_inline_decode().
> When passed a length of zero, xdr_inline_decode() returns the
> current buffer position, which is valid and matches the behavior
> of hand-coded XDR decoders throughout the kernel.
>
> Fixes: 4b132aacb076 ("tools: Add xdrgen")
> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
> ---
> include/linux/sunrpc/xdrgen/_builtins.h | 20 ++++++++------------
> 1 file changed, 8 insertions(+), 12 deletions(-)
>
> diff --git a/include/linux/sunrpc/xdrgen/_builtins.h b/include/linux/sunrpc/xdrgen/_builtins.h
> index 52ed9a9151c4..a723fb1da9c8 100644
> --- a/include/linux/sunrpc/xdrgen/_builtins.h
> +++ b/include/linux/sunrpc/xdrgen/_builtins.h
> @@ -248,12 +248,10 @@ xdrgen_decode_string(struct xdr_stream *xdr, string *ptr, u32 maxlen)
> return false;
> if (unlikely(maxlen && len > maxlen))
> return false;
> - if (len != 0) {
> - p = xdr_inline_decode(xdr, len);
> - if (unlikely(!p))
> - return false;
> - ptr->data = (unsigned char *)p;
> - }
> + p = xdr_inline_decode(xdr, len);
> + if (unlikely(!p))
> + return false;
> + ptr->data = (unsigned char *)p;
> ptr->len = len;
> return true;
> }
> @@ -279,12 +277,10 @@ xdrgen_decode_opaque(struct xdr_stream *xdr, opaque *ptr, u32 maxlen)
> return false;
> if (unlikely(maxlen && len > maxlen))
> return false;
> - if (len != 0) {
> - p = xdr_inline_decode(xdr, len);
> - if (unlikely(!p))
> - return false;
> - ptr->data = (u8 *)p;
> - }
> + p = xdr_inline_decode(xdr, len);
> + if (unlikely(!p))
> + return false;
> + ptr->data = (u8 *)p;
> ptr->len = len;
> return true;
> }
Reviewed-by: Jeff Layton <jlayton@kernel.org>
next prev parent reply other threads:[~2025-12-22 12:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-20 15:41 [PATCH] SUNRPC: xdrgen: Initialize data pointer for zero-length items Chuck Lever
2025-12-22 12:47 ` Jeff Layton [this message]
2025-12-27 4:49 ` NeilBrown
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=e8bbc54e23e1c38a1eb2d41a6550c3908f87a215.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=cel@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=dai.ngo@oracle.com \
--cc=linux-nfs@vger.kernel.org \
--cc=neilb@ownmail.net \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox