From patchwork Tue Apr 18 00:25:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 9684763 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4C3A460375 for ; Tue, 18 Apr 2017 00:26:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3388E27C05 for ; Tue, 18 Apr 2017 00:26:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27CEB27FA8; Tue, 18 Apr 2017 00:26:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_TVD_MIME_EPI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA99C28113 for ; Tue, 18 Apr 2017 00:26:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752773AbdDRA0B (ORCPT ); Mon, 17 Apr 2017 20:26:01 -0400 Received: from mx2.suse.de ([195.135.220.15]:56425 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751528AbdDRA0A (ORCPT ); Mon, 17 Apr 2017 20:26:00 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 8627CABA2; Tue, 18 Apr 2017 00:25:59 +0000 (UTC) From: NeilBrown To: "J. Bruce Fields" , linux-nfs@vger.kernel.org Date: Tue, 18 Apr 2017 10:25:20 +1000 Cc: Neil Brown Subject: Re: [PATCH] nfsd: check for oversized NFSv2/v3 arguments In-Reply-To: <20170414150940.GB5362@fieldses.org> References: <20170414150440.GA5362@fieldses.org> <20170414150940.GB5362@fieldses.org> Message-ID: <87h91mtvdb.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Fri, Apr 14 2017, J. Bruce Fields wrote: > (Cc'd you, Neil, partly on the off chance you might have a better idea > where this came from. Looks to me like it may have been there forever, > but, I haven't looked too hard yet.) > Hi Bruce, I can't say that I like this patch at all. The problem is that: pages = size / PAGE_SIZE + 1; /* extra page as we hold both request and reply. * We assume one is at most one page */ this assumption is never verified. To my mind, the "obvious" way to verify this assumption is that an attempt to generate a multi-page reply should fail if there was a multi-page request. Failing if there was a little bit of extra noise at the end of the request seems harsher than necessary, and could result in a regression. We already know how big replies can get, so we can perform a complete sanity check quite early: I haven't tested this at all and haven't even convinced myself that it covers every case (though I cannot immediately think of any likely corners). Does it address your test case? Thanks, NeilBrown diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index a08aeb56b8e4..14f4d425cf8c 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -1196,6 +1196,12 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv) goto err_bad_proc; rqstp->rq_procinfo = procp; + if ((procp->pc_xdrressize == 0 || + procp->pc_xdrressize > XDR_QUADLEN(PAGE_SIZE)) && + rqstp->rq_arg.len > PAGE_SIZE) + /* The assumption about request/reply sizes in svc_init_buffer() is violated! */ + goto err_garbage; + /* Syntactic check complete */ serv->sv_stats->rpccnt++;