Skip to content

Commit 3f96502

Browse files
committed
NFSD: COMMIT operations must not return NFS?ERR_INVAL
Since, well, forever, the Linux NFS server's nfsd_commit() function has returned nfserr_inval when the passed-in byte range arguments were non-sensical. However, according to RFC 1813 section 3.3.21, NFSv3 COMMIT requests are permitted to return only the following non-zero status codes: NFS3ERR_IO NFS3ERR_STALE NFS3ERR_BADHANDLE NFS3ERR_SERVERFAULT NFS3ERR_INVAL is not included in that list. Likewise, NFS4ERR_INVAL is not listed in the COMMIT row of Table 6 in RFC 8881. RFC 7530 does permit COMMIT to return NFS4ERR_INVAL, but does not specify when it can or should be used. Instead of dropping or failing a COMMIT request in a byte range that is not supported, turn it into a valid request by treating one or both arguments as zero. Offset zero means start-of-file, count zero means until-end-of-file, so we only ever extend the commit range. NFS servers are always allowed to commit more and sooner than requested. The range check is no longer bounded by NFS_OFFSET_MAX, but rather by the value that is returned in the maxfilesize field of the NFSv3 FSINFO procedure or the NFSv4 maxfilesize file attribute. Note that this change results in a new pynfs failure: CMT4 st_commit.testCommitOverflow : RUNNING CMT4 st_commit.testCommitOverflow : FAILURE COMMIT with offset + count overflow should return NFS4ERR_INVAL, instead got NFS4_OK IMO the test is not correct as written: RFC 8881 does not allow the COMMIT operation to return NFS4ERR_INVAL. Reported-by: Dan Aloni <dan.aloni@vastdata.com> Cc: stable@vger.kernel.org Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Reviewed-by: Bruce Fields <bfields@fieldses.org>
1 parent 6260d9a commit 3f96502

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

fs/nfsd/nfs3proc.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -663,15 +663,9 @@ nfsd3_proc_commit(struct svc_rqst *rqstp)
663663
argp->count,
664664
(unsigned long long) argp->offset);
665665

666-
if (argp->offset > NFS_OFFSET_MAX) {
667-
resp->status = nfserr_inval;
668-
goto out;
669-
}
670-
671666
fh_copy(&resp->fh, &argp->fh);
672667
resp->status = nfsd_commit(rqstp, &resp->fh, argp->offset,
673668
argp->count, resp->verf);
674-
out:
675669
return rpc_success;
676670
}
677671

fs/nfsd/vfs.c

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,42 +1114,61 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
11141114
}
11151115

11161116
#ifdef CONFIG_NFSD_V3
1117-
/*
1118-
* Commit all pending writes to stable storage.
1117+
/**
1118+
* nfsd_commit - Commit pending writes to stable storage
1119+
* @rqstp: RPC request being processed
1120+
* @fhp: NFS filehandle
1121+
* @offset: raw offset from beginning of file
1122+
* @count: raw count of bytes to sync
1123+
* @verf: filled in with the server's current write verifier
11191124
*
1120-
* Note: we only guarantee that data that lies within the range specified
1121-
* by the 'offset' and 'count' parameters will be synced.
1125+
* Note: we guarantee that data that lies within the range specified
1126+
* by the 'offset' and 'count' parameters will be synced. The server
1127+
* is permitted to sync data that lies outside this range at the
1128+
* same time.
11221129
*
11231130
* Unfortunately we cannot lock the file to make sure we return full WCC
11241131
* data to the client, as locking happens lower down in the filesystem.
1132+
*
1133+
* Return values:
1134+
* An nfsstat value in network byte order.
11251135
*/
11261136
__be32
1127-
nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp,
1128-
loff_t offset, unsigned long count, __be32 *verf)
1137+
nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp, u64 offset,
1138+
u32 count, __be32 *verf)
11291139
{
1140+
u64 maxbytes;
1141+
loff_t start, end;
11301142
struct nfsd_net *nn;
11311143
struct nfsd_file *nf;
1132-
loff_t end = LLONG_MAX;
1133-
__be32 err = nfserr_inval;
1134-
1135-
if (offset < 0)
1136-
goto out;
1137-
if (count != 0) {
1138-
end = offset + (loff_t)count - 1;
1139-
if (end < offset)
1140-
goto out;
1141-
}
1144+
__be32 err;
11421145

11431146
err = nfsd_file_acquire(rqstp, fhp,
11441147
NFSD_MAY_WRITE|NFSD_MAY_NOT_BREAK_LEASE, &nf);
11451148
if (err)
11461149
goto out;
1150+
1151+
/*
1152+
* Convert the client-provided (offset, count) range to a
1153+
* (start, end) range. If the client-provided range falls
1154+
* outside the maximum file size of the underlying FS,
1155+
* clamp the sync range appropriately.
1156+
*/
1157+
start = 0;
1158+
end = LLONG_MAX;
1159+
maxbytes = (u64)fhp->fh_dentry->d_sb->s_maxbytes;
1160+
if (offset < maxbytes) {
1161+
start = offset;
1162+
if (count && (offset + count - 1 < maxbytes))
1163+
end = offset + count - 1;
1164+
}
1165+
11471166
nn = net_generic(nf->nf_net, nfsd_net_id);
11481167
if (EX_ISSYNC(fhp->fh_export)) {
11491168
errseq_t since = READ_ONCE(nf->nf_file->f_wb_err);
11501169
int err2;
11511170

1152-
err2 = vfs_fsync_range(nf->nf_file, offset, end, 0);
1171+
err2 = vfs_fsync_range(nf->nf_file, start, end, 0);
11531172
switch (err2) {
11541173
case 0:
11551174
nfsd_copy_write_verifier(verf, nn);

fs/nfsd/vfs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ __be32 do_nfsd_create(struct svc_rqst *, struct svc_fh *,
7474
char *name, int len, struct iattr *attrs,
7575
struct svc_fh *res, int createmode,
7676
u32 *verifier, bool *truncp, bool *created);
77-
__be32 nfsd_commit(struct svc_rqst *, struct svc_fh *,
78-
loff_t, unsigned long, __be32 *verf);
77+
__be32 nfsd_commit(struct svc_rqst *rqst, struct svc_fh *fhp,
78+
u64 offset, u32 count, __be32 *verf);
7979
#endif /* CONFIG_NFSD_V3 */
8080
#ifdef CONFIG_NFSD_V4
8181
__be32 nfsd_getxattr(struct svc_rqst *rqstp, struct svc_fh *fhp,

0 commit comments

Comments
 (0)