Commit 24d92de9 authored by Trond Myklebust's avatar Trond Myklebust Committed by Chuck Lever
Browse files

nfsd: Fix NFSv3 atomicity bugs in nfsd_setattr()



The main point of the guarded SETATTR is to prevent races with other
WRITE and SETATTR calls. That requires that the check of the guard time
against the inode ctime be done after taking the inode lock.

Furthermore, we need to take into account the 32-bit nature of
timestamps in NFSv3, and the possibility that files may change at a
faster rate than once a second.

Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
Reviewed-by: default avatarNeilBrown <neilb@suse.de>
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
parent 6412e44c
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -71,13 +71,15 @@ nfsd3_proc_setattr(struct svc_rqst *rqstp)
	struct nfsd_attrs attrs = {
		.na_iattr	= &argp->attrs,
	};
	const struct timespec64 *guardtime = NULL;

	dprintk("nfsd: SETATTR(3)  %s\n",
				SVCFH_fmt(&argp->fh));

	fh_copy(&resp->fh, &argp->fh);
	resp->status = nfsd_setattr(rqstp, &resp->fh, &attrs,
				    argp->check_guard, argp->guardtime);
	if (argp->check_guard)
		guardtime = &argp->guardtime;
	resp->status = nfsd_setattr(rqstp, &resp->fh, &attrs, guardtime);
	return rpc_success;
}

+1 −4
Original line number Diff line number Diff line
@@ -295,17 +295,14 @@ svcxdr_decode_sattr3(struct svc_rqst *rqstp, struct xdr_stream *xdr,
static bool
svcxdr_decode_sattrguard3(struct xdr_stream *xdr, struct nfsd3_sattrargs *args)
{
	__be32 *p;
	u32 check;

	if (xdr_stream_decode_bool(xdr, &check) < 0)
		return false;
	if (check) {
		p = xdr_inline_decode(xdr, XDR_UNIT * 2);
		if (!p)
		if (!svcxdr_decode_nfstime3(xdr, &args->guardtime))
			return false;
		args->check_guard = 1;
		args->guardtime = be32_to_cpup(p);
	} else
		args->check_guard = 0;

+1 −2
Original line number Diff line number Diff line
@@ -1171,8 +1171,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
		goto out;
	save_no_wcc = cstate->current_fh.fh_no_wcc;
	cstate->current_fh.fh_no_wcc = true;
	status = nfsd_setattr(rqstp, &cstate->current_fh, &attrs,
				0, (time64_t)0);
	status = nfsd_setattr(rqstp, &cstate->current_fh, &attrs, NULL);
	cstate->current_fh.fh_no_wcc = save_no_wcc;
	if (!status)
		status = nfserrno(attrs.na_labelerr);
+1 −1
Original line number Diff line number Diff line
@@ -5460,7 +5460,7 @@ nfsd4_truncate(struct svc_rqst *rqstp, struct svc_fh *fh,
		return 0;
	if (!(open->op_share_access & NFS4_SHARE_ACCESS_WRITE))
		return nfserr_inval;
	return nfsd_setattr(rqstp, fh, &attrs, 0, (time64_t)0);
	return nfsd_setattr(rqstp, fh, &attrs, NULL);
}

static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
+3 −3
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ nfsd_proc_setattr(struct svc_rqst *rqstp)
		}
	}

	resp->status = nfsd_setattr(rqstp, fhp, &attrs, 0, (time64_t)0);
	resp->status = nfsd_setattr(rqstp, fhp, &attrs, NULL);
	if (resp->status != nfs_ok)
		goto out;

@@ -390,8 +390,8 @@ nfsd_proc_create(struct svc_rqst *rqstp)
		 */
		attr->ia_valid &= ATTR_SIZE;
		if (attr->ia_valid)
			resp->status = nfsd_setattr(rqstp, newfhp, &attrs, 0,
						    (time64_t)0);
			resp->status = nfsd_setattr(rqstp, newfhp, &attrs,
						    NULL);
	}

out_unlock:
Loading