Re: [PATCH v3 3/3] nfsd: use NSEC_PER_SEC in nfsd4_decode_nfstime4()

Jeff Layton <[email protected]>
Newsgroups gmane.linux.nfs
Message-ID <[email protected]>
On Tue, 2026-06-16 at 13:40 +0800, robbieko wrote:
> From: Robbie Ko <robbieko-UelDjCVBxVpWk0Htik3J/[email protected]>
> 
> nfsd4_decode_nfstime4() open-codes the nanoseconds upper bound as the
> literal (u32)1000000000. Use the named constant NSEC_PER_SEC instead,
> matching the NFSv3 setattr check and improving readability.
> 
> The original code cast the literal to u32 to force an unsigned
> comparison, which matters on 32-bit where tv_nsec is a 32-bit signed
> long: an out-of-range u32 wire nseconds (>= 0x80000000) assigned to it
> becomes negative and a signed compare against NSEC_PER_SEC (a signed
> long) would wrongly pass. Keep that protection by casting tv_nsec to
> unsigned long, the same width as tv_nsec, matching timespec64_valid().
> No functional change.
> 
> Signed-off-by: Robbie Ko <robbieko-UelDjCVBxVpWk0Htik3J/[email protected]>
> ---
>  fs/nfsd/nfs4xdr.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
> index 2a0946c630e1..db17bd3e45d6 100644
> --- a/fs/nfsd/nfs4xdr.c
> +++ b/fs/nfsd/nfs4xdr.c
> @@ -244,7 +244,7 @@ nfsd4_decode_nfstime4(struct nfsd4_compoundargs *argp, struct timespec64 *tv)
>  		return nfserr_bad_xdr;
>  	p = xdr_decode_hyper(p, &tv->tv_sec);
>  	tv->tv_nsec = be32_to_cpup(p++);
> -	if (tv->tv_nsec >= (u32)1000000000)
> +	if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
>  		return nfserr_inval;
>  	return nfs_ok;
>  }

Reviewed-by: Jeff Layton <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.