Skip to content

Commit 6260d9a

Browse files
committed
NFSD: Clamp WRITE offsets
Ensure that a client cannot specify a WRITE range that falls in a byte range outside what the kernel's internal types (such as loff_t, which is signed) can represent. The kiocb iterators, invoked in nfsd_vfs_write(), should properly limit write operations to within the underlying file system's s_maxbytes. Cc: stable@vger.kernel.org Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent a648fde commit 6260d9a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

fs/nfsd/nfs3proc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ nfsd3_proc_write(struct svc_rqst *rqstp)
203203
(unsigned long long) argp->offset,
204204
argp->stable? " stable" : "");
205205

206+
resp->status = nfserr_fbig;
207+
if (argp->offset > (u64)OFFSET_MAX ||
208+
argp->offset + argp->len > (u64)OFFSET_MAX)
209+
return rpc_success;
210+
206211
fh_copy(&resp->fh, &argp->fh);
207212
resp->committed = argp->stable;
208213
nvecs = svc_fill_write_vector(rqstp, &argp->payload);

fs/nfsd/nfs4proc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,9 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
10221022
unsigned long cnt;
10231023
int nvecs;
10241024

1025-
if (write->wr_offset >= OFFSET_MAX)
1026-
return nfserr_inval;
1025+
if (write->wr_offset > (u64)OFFSET_MAX ||
1026+
write->wr_offset + write->wr_buflen > (u64)OFFSET_MAX)
1027+
return nfserr_fbig;
10271028

10281029
cnt = write->wr_buflen;
10291030
trace_nfsd_write_start(rqstp, &cstate->current_fh,

0 commit comments

Comments
 (0)