Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 5 Aug 2018 19:21:51 +0000 (UTC)
From:      Rick Macklem <rmacklem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r337357 - head/sys/fs/nfsserver
Message-ID:  <201808051921.w75JLpvQ014548@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rmacklem
Date: Sun Aug  5 19:21:50 2018
New Revision: 337357
URL: https://svnweb.freebsd.org/changeset/base/337357

Log:
  Copy all bits of a file handle in case there is padding in the structure.
  
  At least on x86, fhandle_t is a packed structure, so I believe an
  assignment will copy all the bits. However, for some current/future
  architectures, there might be padding in the structure that doesn't get
  copied via an assignment.
  Since NFS assumes a file handle is an opaque blob of bits that can be
  compared via memcmp()/bcmp(), all the bits including any padding must be
  copied.
  This patch replaces the assignments with a call to a byte copy function.
  Spotted during code inspection.

Modified:
  head/sys/fs/nfsserver/nfs_nfsdport.c
  head/sys/fs/nfsserver/nfs_nfsdstate.c

Modified: head/sys/fs/nfsserver/nfs_nfsdport.c
==============================================================================
--- head/sys/fs/nfsserver/nfs_nfsdport.c	Sun Aug  5 19:17:07 2018	(r337356)
+++ head/sys/fs/nfsserver/nfs_nfsdport.c	Sun Aug  5 19:21:50 2018	(r337357)
@@ -3954,7 +3954,7 @@ nfsrv_pnfscreate(struct vnode *vp, struct vattr *vap, 
 		tdsc->p = p;
 		tdsc->pf = tpf;
 		tdsc->createva = *vap;
-		tdsc->fh = fh;
+		NFSBCOPY(&fh, &tdsc->fh, sizeof(fh));
 		tdsc->va = va;
 		tdsc->dvp = dvp[i];
 		tdsc->done = 0;
@@ -5014,7 +5014,7 @@ nfsrv_writedsrpc(fhandle_t *fhp, off_t off, int len, s
 	error = 0;
 	for (i = 0; i < mirrorcnt - 1; i++, tdrpc++) {
 		tdrpc->done = 0;
-		tdrpc->fh = *fhp;
+		NFSBCOPY(fhp, &tdrpc->fh, sizeof(*fhp));
 		tdrpc->off = off;
 		tdrpc->len = len;
 		tdrpc->nmp = *nmpp;
@@ -5200,7 +5200,7 @@ nfsrv_setattrdsrpc(fhandle_t *fhp, struct ucred *cred,
 	for (i = 0; i < mirrorcnt - 1; i++, tdrpc++) {
 		tdrpc->done = 0;
 		tdrpc->inprog = 0;
-		tdrpc->fh = *fhp;
+		NFSBCOPY(fhp, &tdrpc->fh, sizeof(*fhp));
 		tdrpc->nmp = *nmpp;
 		tdrpc->vp = vp;
 		tdrpc->cred = cred;
@@ -5348,7 +5348,7 @@ nfsrv_setacldsrpc(fhandle_t *fhp, struct ucred *cred, 
 	for (i = 0; i < mirrorcnt - 1; i++, tdrpc++) {
 		tdrpc->done = 0;
 		tdrpc->inprog = 0;
-		tdrpc->fh = *fhp;
+		NFSBCOPY(fhp, &tdrpc->fh, sizeof(*fhp));
 		tdrpc->nmp = *nmpp;
 		tdrpc->vp = vp;
 		tdrpc->cred = cred;

Modified: head/sys/fs/nfsserver/nfs_nfsdstate.c
==============================================================================
--- head/sys/fs/nfsserver/nfs_nfsdstate.c	Sun Aug  5 19:17:07 2018	(r337356)
+++ head/sys/fs/nfsserver/nfs_nfsdstate.c	Sun Aug  5 19:21:50 2018	(r337357)
@@ -6907,7 +6907,7 @@ nfsrv_recalloldlayout(NFSPROC_T *p)
 				lyp->lay_stateid.seqid = 1;
 			clientid = lyp->lay_clientid;
 			stateid = lyp->lay_stateid;
-			fh = lyp->lay_fh;
+			NFSBCOPY(&lyp->lay_fh, &fh, sizeof(fh));
 			laytype = lyp->lay_type;
 			break;
 		}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808051921.w75JLpvQ014548>