lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a7f6e186-ad9c-47eb-88d7-64605d7a7854@oracle.com>
Date: Thu, 17 Jul 2025 16:08:07 -0400
From: Chuck Lever <chuck.lever@...cle.com>
To: Sergey Bashirov <sergeybashirov@...il.com>,
        Dan Carpenter <dan.carpenter@...aro.org>,
        Jeff Layton <jlayton@...nel.org>, NeilBrown <neil@...wn.name>,
        Olga Kornievskaia <okorniev@...hat.com>, Dai Ngo <Dai.Ngo@...cle.com>,
        Tom Talpey <tom@...pey.com>
Cc: linux-nfs@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] NFSD: Change ret code of xdr_stream_decode_opaque_fixed

On 7/17/25 3:48 PM, Sergey Bashirov wrote:
> Since the XDR field is fixed in size, the caller already knows how many
> bytes were decoded, on success. Thus, xdr_stream_decode_opaque_fixed()
> doesn't need to return that value. And, xdr_stream_decode_u32 and _u64
> both return zero on success.
> 
> This patch also simplifies the error checking to avoid potential integer
> promotion issues.
> 
> Signed-off-by: Sergey Bashirov <sergeybashirov@...il.com>
> ---
>  fs/nfsd/blocklayoutxdr.c                                      | 2 +-
>  include/linux/nfs_xdr.h                                       | 2 +-
>  include/linux/sunrpc/xdr.h                                    | 4 ++--
>  .../xdrgen/templates/C/pointer/decoder/fixed_length_opaque.j2 | 2 +-
>  .../xdrgen/templates/C/struct/decoder/fixed_length_opaque.j2  | 2 +-
>  .../xdrgen/templates/C/typedef/decoder/fixed_length_opaque.j2 | 2 +-
>  6 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/nfsd/blocklayoutxdr.c b/fs/nfsd/blocklayoutxdr.c
> index 266b2737882e1..2a4dcb428d823 100644
> --- a/fs/nfsd/blocklayoutxdr.c
> +++ b/fs/nfsd/blocklayoutxdr.c
> @@ -157,7 +157,7 @@ nfsd4_block_decode_layoutupdate(struct xdr_stream *xdr, struct iomap **iomapp,
>  
>  		ret = xdr_stream_decode_opaque_fixed(xdr,
>  				&bex.vol_id, sizeof(bex.vol_id));
> -		if (ret < sizeof(bex.vol_id)) {
> +		if (ret) {

I've dropped "nfsd: Implement large extent array support in pNFS" from
nfsd-next because of the number of (minor) issues that have been found
so far.

Also, I think this patch needs to come before "Implement large extent",
and so does the forthcoming patch that moves nfsd4_decode_deviceid4().

So, please rebase this one today's nfsd-next.


>  			nfserr = nfserr_bad_xdr;
>  			goto fail;
>  		}
> diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
> index 67f6632f723b4..dd80163e0140c 100644
> --- a/include/linux/nfs_xdr.h
> +++ b/include/linux/nfs_xdr.h
> @@ -1863,7 +1863,7 @@ static inline int decode_opaque_fixed(struct xdr_stream *xdr,
>  				      void *buf, size_t len)
>  {
>  	ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
> -	if (unlikely(ret < 0))
> +	if (unlikely(ret))

Unless I've misunderstood Dan's bug report, I don't think these
call sites need to change ... The compiler should promote the
naked integer to the proper integer type so that the less-than
comparison is still valid.


>  		return -EIO;
>  	return 0;
>  }
> diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h
> index e3358c630ba18..ffb699a02b17d 100644
> --- a/include/linux/sunrpc/xdr.h
> +++ b/include/linux/sunrpc/xdr.h
> @@ -730,7 +730,7 @@ xdr_stream_decode_u64(struct xdr_stream *xdr, __u64 *ptr)
>   * @len: size of buffer pointed to by @ptr
>   *
>   * Return values:
> - *   On success, returns size of object stored in @ptr
> + *   %0 on success
>   *   %-EBADMSG on XDR buffer overflow
>   */
>  static inline ssize_t
> @@ -741,7 +741,7 @@ xdr_stream_decode_opaque_fixed(struct xdr_stream *xdr, void *ptr, size_t len)
>  	if (unlikely(!p))
>  		return -EBADMSG;
>  	xdr_decode_opaque_fixed(p, ptr, len);
> -	return len;
> +	return 0;
>  }
>  
>  /**
> diff --git a/tools/net/sunrpc/xdrgen/templates/C/pointer/decoder/fixed_length_opaque.j2 b/tools/net/sunrpc/xdrgen/templates/C/pointer/decoder/fixed_length_opaque.j2
> index b4695ece1884b..ea9295f91aecc 100644
> --- a/tools/net/sunrpc/xdrgen/templates/C/pointer/decoder/fixed_length_opaque.j2
> +++ b/tools/net/sunrpc/xdrgen/templates/C/pointer/decoder/fixed_length_opaque.j2
> @@ -2,5 +2,5 @@
>  {% if annotate %}
>  	/* member {{ name }} (fixed-length opaque) */
>  {% endif %}
> -	if (xdr_stream_decode_opaque_fixed(xdr, ptr->{{ name }}, {{ size }}) < 0)
> +	if (xdr_stream_decode_opaque_fixed(xdr, ptr->{{ name }}, {{ size }}) != 0)

Ditto.


>  		return false;
> diff --git a/tools/net/sunrpc/xdrgen/templates/C/struct/decoder/fixed_length_opaque.j2 b/tools/net/sunrpc/xdrgen/templates/C/struct/decoder/fixed_length_opaque.j2
> index b4695ece1884b..ea9295f91aecc 100644
> --- a/tools/net/sunrpc/xdrgen/templates/C/struct/decoder/fixed_length_opaque.j2
> +++ b/tools/net/sunrpc/xdrgen/templates/C/struct/decoder/fixed_length_opaque.j2
> @@ -2,5 +2,5 @@
>  {% if annotate %}
>  	/* member {{ name }} (fixed-length opaque) */
>  {% endif %}
> -	if (xdr_stream_decode_opaque_fixed(xdr, ptr->{{ name }}, {{ size }}) < 0)
> +	if (xdr_stream_decode_opaque_fixed(xdr, ptr->{{ name }}, {{ size }}) != 0)
>  		return false;

Ditto.


> diff --git a/tools/net/sunrpc/xdrgen/templates/C/typedef/decoder/fixed_length_opaque.j2 b/tools/net/sunrpc/xdrgen/templates/C/typedef/decoder/fixed_length_opaque.j2
> index 8b4ff08c49e5e..bdc7bd24ffb13 100644
> --- a/tools/net/sunrpc/xdrgen/templates/C/typedef/decoder/fixed_length_opaque.j2
> +++ b/tools/net/sunrpc/xdrgen/templates/C/typedef/decoder/fixed_length_opaque.j2
> @@ -13,5 +13,5 @@ xdrgen_decode_{{ name }}(struct xdr_stream *xdr, {{ classifier }}{{ name }} *ptr
>  {% if annotate %}
>  	/* (fixed-length opaque) */
>  {% endif %}
> -	return xdr_stream_decode_opaque_fixed(xdr, ptr, {{ size }}) >= 0;
> +	return xdr_stream_decode_opaque_fixed(xdr, ptr, {{ size }}) == 0;
>  };

The existing comparison will work fine. But "== 0" will match the new
return values better. LGTM.


-- 
Chuck Lever

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ