aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorJ. Bruce Fields <bfields@redhat.com>2017-04-21 16:10:18 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-05-03 11:36:38 -0400
commitfc6445df466f37291a70937642068bda78802a5b (patch)
tree6cc6d7f8d665027eeb17aa94094fc81a5f43cfb4 /fs
parentb88e4113250dd9d2789ba64d7136ccf4b49855f4 (diff)
nfsd: check for oversized NFSv2/v3 arguments
commit e6838a29ecb484c97e4efef9429643b9851fba6e upstream. A client can append random data to the end of an NFSv2 or NFSv3 RPC call without our complaining; we'll just stop parsing at the end of the expected data and ignore the rest. Encoded arguments and replies are stored together in an array of pages, and if a call is too large it could leave inadequate space for the reply. This is normally OK because NFS RPC's typically have either short arguments and long replies (like READ) or long arguments and short replies (like WRITE). But a client that sends an incorrectly long reply can violate those assumptions. This was observed to cause crashes. Also, several operations increment rq_next_page in the decode routine before checking the argument size, which can leave rq_next_page pointing well past the end of the page array, causing trouble later in svc_free_pages. So, following a suggestion from Neil Brown, add a central check to enforce our expectation that no NFSv2/v3 call has both a large call and a large reply. As followup we may also want to rewrite the encoding routines to check more carefully that they aren't running off the end of the page array. We may also consider rejecting calls that have any extra garbage appended. That would be safer, and within our rights by spec, but given the age of our server and the NFS protocol, and the fact that we've never enforced this before, we may need to balance that against the possibility of breaking some oddball client. Reported-by: Tuomas Haanpää <thaan@synopsys.com> Reported-by: Ari Kauppi <ari@synopsys.com> Reviewed-by: NeilBrown <neilb@suse.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/nfsd/nfssvc.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
index a2b65fc56dd6..1645b977c9c6 100644
--- a/fs/nfsd/nfssvc.c
+++ b/fs/nfsd/nfssvc.c
@@ -733,6 +733,37 @@ static __be32 map_new_errors(u32 vers, __be32 nfserr)
733 return nfserr; 733 return nfserr;
734} 734}
735 735
736/*
737 * A write procedure can have a large argument, and a read procedure can
738 * have a large reply, but no NFSv2 or NFSv3 procedure has argument and
739 * reply that can both be larger than a page. The xdr code has taken
740 * advantage of this assumption to be a sloppy about bounds checking in
741 * some cases. Pending a rewrite of the NFSv2/v3 xdr code to fix that
742 * problem, we enforce these assumptions here:
743 */
744static bool nfs_request_too_big(struct svc_rqst *rqstp,
745 struct svc_procedure *proc)
746{
747 /*
748 * The ACL code has more careful bounds-checking and is not
749 * susceptible to this problem:
750 */
751 if (rqstp->rq_prog != NFS_PROGRAM)
752 return false;
753 /*
754 * Ditto NFSv4 (which can in theory have argument and reply both
755 * more than a page):
756 */
757 if (rqstp->rq_vers >= 4)
758 return false;
759 /* The reply will be small, we're OK: */
760 if (proc->pc_xdrressize > 0 &&
761 proc->pc_xdrressize < XDR_QUADLEN(PAGE_SIZE))
762 return false;
763
764 return rqstp->rq_arg.len > PAGE_SIZE;
765}
766
736int 767int
737nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp) 768nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp)
738{ 769{
@@ -745,6 +776,11 @@ nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp)
745 rqstp->rq_vers, rqstp->rq_proc); 776 rqstp->rq_vers, rqstp->rq_proc);
746 proc = rqstp->rq_procinfo; 777 proc = rqstp->rq_procinfo;
747 778
779 if (nfs_request_too_big(rqstp, proc)) {
780 dprintk("nfsd: NFSv%d argument too large\n", rqstp->rq_vers);
781 *statp = rpc_garbage_args;
782 return 1;
783 }
748 /* 784 /*
749 * Give the xdr decoder a chance to change this if it wants 785 * Give the xdr decoder a chance to change this if it wants
750 * (necessary in the NFSv4.0 compound case) 786 * (necessary in the NFSv4.0 compound case)