From nobody Mon Jan 3 05:44:30 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 8E979193F177; Mon, 3 Jan 2022 05:44:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JS4SZ2BtDz3nCR; Mon, 3 Jan 2022 05:44:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2B0AF1F964; Mon, 3 Jan 2022 05:44:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2035iUS6011955; Mon, 3 Jan 2022 05:44:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2035iUbv011954; Mon, 3 Jan 2022 05:44:30 GMT (envelope-from git) Date: Mon, 3 Jan 2022 05:44:30 GMT Message-Id: <202201030544.2035iUbv011954@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alan Somers Subject: git: 374e8226d225 - stable/12 - nfs: don't truncate directory cookies to 32-bits in the NFS server List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: asomers X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 374e8226d2252da6421a05313a7ac223fc00c432 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1641188670; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+2a9iNcH3o45AZKgA48nncbkB7W1xNcHvmEpPIVCt0Q=; b=bGBT9ZStyMAbBtoSd9562hYP0qaWDProg2uVcmUHWvKXNuWfjGK+Zr6oCMIClHAvk1+uG7 bF2kGe9Y4EP/iGjcwKXaaU2z03P/PO8WVkt1viMmajQrKSOeE/jYrnDeuPT/wf6WtOHmBi ka4LDjYFSIE0BqT03Dti/w95jeZn7+OOJuqAKMjRW1D01jMM7tkz9W3YFsFAhj7gi2fb3X OT3IlS+V28tOW85wi04GXSEdlqKtue8QfkbKn2LbGLpF7gEDZFIuXKB4Ic0sR8N4KImTr/ kDYAdKzDkDV5CcWQZIKl1tVGEKKqnWGjTVv/tYG+YXfi6R3GhWLBPuOrlyagDw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1641188670; a=rsa-sha256; cv=none; b=NDEFNNXyTCnKaXtMIfdGJoj0Fb0C7I8x8Vdr/C5mPRKiRMp9cYwggBK4G8Pg2L1cdLcf1v 4LVp8Rfa1VMHbj9bFc29r70pdOG5Z6/hFMJCcKEziOYXhlbu0NGucQgL8YUFe/qF2JtwYo q0/LEx/sYGQyVJPr/CSsDSnZB0BFjPYJBYm3MlQncB+n/57Qt4Vi6+AFZYrIh6VIAgdjKI xSZkQkRvls27CtfyXCgCHtOF9lFNSgXpHgSG7JFvmeH8oqc+kKOD7968ktk7rT5ozphOiT 43rRlrZJGfbgBXbLUOAslZuT2mytwGqpy8SGtUYsqsF6mSPugeXZgMzDMEkYEw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=374e8226d2252da6421a05313a7ac223fc00c432 commit 374e8226d2252da6421a05313a7ac223fc00c432 Author: Alan Somers AuthorDate: 2021-12-13 03:57:14 +0000 Commit: Alan Somers CommitDate: 2022-01-03 05:37:51 +0000 nfs: don't truncate directory cookies to 32-bits in the NFS server In NFSv2, the directory cookie was 32-bits. NFSv3 widened it to 64-bits and SVN r22521 widened the corresponding argument in VOP_READDIR, but FreeBSD's NFS server continued to treat the cookies as 32-bits, and 0-extended to fill the field on the wire. Nobody ever noticed, because every in-tree file system generates cookies that fit comfortably within 32-bits. Also, have better type safety for txdr_hyper. Turn it into an inline function that type-checks its arguments. Prevents warnings about shift-count-overflow. PR: 260375 Reviewed by: rmacklem Differential Revision: https://reviews.freebsd.org/D33404 (cherry picked from commit 32fbc5d824f51f97220bc5c61a23e0bf3ff2b470) --- sys/fs/nfs/xdr_subs.h | 10 ++++++---- sys/fs/nfsserver/nfs_nfsdport.c | 13 ++++++------- sys/fs/nfsserver/nfs_nfsdsubs.c | 6 +++--- sys/nfs/xdr_subs.h | 12 +++++++----- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/sys/fs/nfs/xdr_subs.h b/sys/fs/nfs/xdr_subs.h index 54c7d914983e..9a6d4608d5f1 100644 --- a/sys/fs/nfs/xdr_subs.h +++ b/sys/fs/nfs/xdr_subs.h @@ -93,9 +93,11 @@ ((((u_quad_t)ntohl(((u_int32_t *)(f))[0])) << 32) | \ (u_quad_t)(ntohl(((u_int32_t *)(f))[1]))) -#define txdr_hyper(f, t) do { \ - ((u_int32_t *)(t))[0] = htonl((u_int32_t)((f) >> 32)); \ - ((u_int32_t *)(t))[1] = htonl((u_int32_t)((f) & 0xffffffff)); \ - } while (0) +static inline void +txdr_hyper(uint64_t f, uint32_t* t) +{ + t[0] = htonl((u_int32_t)(f >> 32)); + t[1] = htonl((u_int32_t)(f & 0xffffffff)); +} #endif /* _NFS_XDR_SUBS_H_ */ diff --git a/sys/fs/nfsserver/nfs_nfsdport.c b/sys/fs/nfsserver/nfs_nfsdport.c index 0bb3edbddec9..0f3852318068 100644 --- a/sys/fs/nfsserver/nfs_nfsdport.c +++ b/sys/fs/nfsserver/nfs_nfsdport.c @@ -2026,10 +2026,11 @@ again: (void) nfsm_strtom(nd, dp->d_name, nlen); if (nd->nd_flag & ND_NFSV3) { NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED); - *tl++ = 0; - } else + txdr_hyper(*cookiep, tl); + } else { NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED); - *tl = txdr_unsigned(*cookiep); + *tl = txdr_unsigned(*cookiep); + } } cpos += dp->d_reclen; dp = (struct dirent *)cpos; @@ -2496,8 +2497,7 @@ again: *tl = txdr_unsigned(dp->d_fileno); dirlen += nfsm_strtom(nd, dp->d_name, nlen); NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED); - *tl++ = 0; - *tl = txdr_unsigned(*cookiep); + txdr_hyper(*cookiep, tl); nfsrv_postopattr(nd, 0, nvap); dirlen += nfsm_fhtom(nd,(u_int8_t *)&nfh,0,1); dirlen += (5*NFSX_UNSIGNED+NFSX_V3POSTOPATTR); @@ -2506,8 +2506,7 @@ again: } else { NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED); *tl++ = newnfs_true; - *tl++ = 0; - *tl = txdr_unsigned(*cookiep); + txdr_hyper(*cookiep, tl); dirlen += nfsm_strtom(nd, dp->d_name, nlen); if (nvp != NULL) { supports_nfsv4acls = diff --git a/sys/fs/nfsserver/nfs_nfsdsubs.c b/sys/fs/nfsserver/nfs_nfsdsubs.c index 9ab5ca174b29..e4dcb77001a6 100644 --- a/sys/fs/nfsserver/nfs_nfsdsubs.c +++ b/sys/fs/nfsserver/nfs_nfsdsubs.c @@ -1394,13 +1394,13 @@ nfsrv_fillattr(struct nfsrv_descript *nd, struct nfsvattr *nvap) if (nd->nd_flag & ND_NFSV3) { fp->fa_type = vtonfsv34_type(nvap->na_type); fp->fa_mode = vtonfsv34_mode(nvap->na_mode); - txdr_hyper(nvap->na_size, &fp->fa3_size); - txdr_hyper(nvap->na_bytes, &fp->fa3_used); + txdr_hyper(nvap->na_size, (uint32_t*)&fp->fa3_size); + txdr_hyper(nvap->na_bytes, (uint32_t*)&fp->fa3_used); fp->fa3_rdev.specdata1 = txdr_unsigned(NFSMAJOR(nvap->na_rdev)); fp->fa3_rdev.specdata2 = txdr_unsigned(NFSMINOR(nvap->na_rdev)); fp->fa3_fsid.nfsuquad[0] = 0; fp->fa3_fsid.nfsuquad[1] = txdr_unsigned(nvap->na_fsid); - txdr_hyper(nvap->na_fileid, &fp->fa3_fileid); + txdr_hyper(nvap->na_fileid, (uint32_t*)&fp->fa3_fileid); txdr_nfsv3time(&nvap->na_atime, &fp->fa3_atime); txdr_nfsv3time(&nvap->na_mtime, &fp->fa3_mtime); txdr_nfsv3time(&nvap->na_ctime, &fp->fa3_ctime); diff --git a/sys/nfs/xdr_subs.h b/sys/nfs/xdr_subs.h index 829711e8ddd5..f5a38277c300 100644 --- a/sys/nfs/xdr_subs.h +++ b/sys/nfs/xdr_subs.h @@ -84,10 +84,12 @@ do { \ #define fxdr_hyper(f) \ ((((u_quad_t)ntohl(((u_int32_t *)(f))[0])) << 32) | \ (u_quad_t)(ntohl(((u_int32_t *)(f))[1]))) -#define txdr_hyper(f, t) \ -do { \ - ((u_int32_t *)(t))[0] = htonl((u_int32_t)((f) >> 32)); \ - ((u_int32_t *)(t))[1] = htonl((u_int32_t)((f) & 0xffffffff)); \ -} while (0) + +static inline void +txdr_hyper(uint64_t f, uint32_t* t) +{ + t[0] = htonl((u_int32_t)(f >> 32)); + t[1] = htonl((u_int32_t)(f & 0xffffffff)); +} #endif