Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1088754rwe; Thu, 1 Sep 2022 12:18:59 -0700 (PDT) X-Google-Smtp-Source: AA6agR5RG4x7wX5YGZAmkW9nZ/r0jC0qwMmNCyVEddnZiCjH3NOAZbmAKhfh4nrlKZqkzPnghlEL X-Received: by 2002:a17:90b:1d01:b0:1fe:56b:530d with SMTP id on1-20020a17090b1d0100b001fe056b530dmr613812pjb.215.1662059938945; Thu, 01 Sep 2022 12:18:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662059938; cv=none; d=google.com; s=arc-20160816; b=Ns/+rfcJI5etzRh5bjcNTun4g+uGNu+2wHvDAUM2jE51sZWSPtMRPl658B7u27E9WB RWB0TJnMH5V0f4RP0vmw9gDH9eUiSWpuRGqmEWY5GBrFC/nNOmuzMnKFixsHs8gn5rCd XcpOTCKhiab+5FsRJYdJE582JgJ7R8hvc28ZeZkWaxgM7O/rFQU9MmfJir+SGXioT5DW dYst/r7Jwn6L2EzuoBMnL3ne6oEcAr7K3PNNb9vHLh9+xeyE2pCvMziDLK8Wfb5d6y7G Nn4tue0xUbTu9Eh9xmRTiM1HN+6PtADef2C9wvgxIlP39D85GBKzBh8Ob4KtkwRhQcBy PWMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:to:from:subject; bh=nrzoaIcuvaLBrlcLehWEFOPHsjC3NSEZsII/rBcdSYE=; b=nhlzwMn0iV1HP1IgNWtsfhyO1Uwyh8tmbnKfEXw1iwj5wXeTiZjRFTSfRO7+pA5S5z 0rJPt+z22q4Zkg3urlX9OiFXYgo9lkB9iTIcDAIMhkVvjiX4u9ItNcuWxtRgMCyFUXrS M5PE+RgLoW+Y/PpDdbDhF3PVhgIthc0+NAydI2lExO7fncn5MEe0yjnbA1qzZkyn9bwz B1AyobN4LiI4d5mcLbx+YjDZLKniQ6gjqXAj0lnw19cxLYJJhaMDSQMujq61mZVC5N67 QA55gJg3xwMH5u5SB+SUWkAfXw194drn6SRlCaxZEOchWz6AY988rVhE6Cfd7UJs1S2w XFRw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ot18-20020a17090b3b5200b001fe3552edf5si5191798pjb.164.2022.09.01.12.18.46; Thu, 01 Sep 2022 12:18:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232987AbiIATK3 (ORCPT + 99 others); Thu, 1 Sep 2022 15:10:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233567AbiIATK3 (ORCPT ); Thu, 1 Sep 2022 15:10:29 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B96D4A821 for ; Thu, 1 Sep 2022 12:10:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1842DB828FF for ; Thu, 1 Sep 2022 19:10:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9E7EC433D6; Thu, 1 Sep 2022 19:10:25 +0000 (UTC) Subject: [PATCH v3 6/6] NFSD: Protect against send buffer overflow in NFSv3 READ From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Thu, 01 Sep 2022 15:10:24 -0400 Message-ID: <166205942489.1435.8984764212504461615.stgit@manet.1015granger.net> In-Reply-To: <166204973526.1435.6068003336048840051.stgit@manet.1015granger.net> References: <166204973526.1435.6068003336048840051.stgit@manet.1015granger.net> User-Agent: StGit/1.5.dev2+g9ce680a5 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Since before the git era, NFSD has conserved the number of pages held by each nfsd thread by combining the RPC receive and send buffers into a single array of pages. This works because there are no cases where an operation needs a large RPC Call message and a large RPC Reply at the same time. Once an RPC Call has been received, svc_process() updates svc_rqst::rq_res to describe the part of rq_pages that can be used for constructing the Reply. This means that the send buffer (rq_res) shrinks when the received RPC record containing the RPC Call is large. A client can force this shrinkage on TCP by sending a correctly- formed RPC Call header contained in an RPC record that is excessively large. The full maximum payload size cannot be constructed in that case. Cc: Signed-off-by: Chuck Lever --- fs/nfsd/nfs3proc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs3proc.c b/fs/nfsd/nfs3proc.c index 7a159785499a..5b1e771238b3 100644 --- a/fs/nfsd/nfs3proc.c +++ b/fs/nfsd/nfs3proc.c @@ -150,7 +150,6 @@ nfsd3_proc_read(struct svc_rqst *rqstp) { struct nfsd3_readargs *argp = rqstp->rq_argp; struct nfsd3_readres *resp = rqstp->rq_resp; - u32 max_blocksize = svc_max_payload(rqstp); unsigned int len; int v; @@ -159,7 +158,8 @@ nfsd3_proc_read(struct svc_rqst *rqstp) (unsigned long) argp->count, (unsigned long long) argp->offset); - argp->count = min_t(u32, argp->count, max_blocksize); + argp->count = min_t(u32, argp->count, svc_max_payload(rqstp)); + argp->count = min_t(u32, argp->count, rqstp->rq_res.buflen); if (argp->offset > (u64)OFFSET_MAX) argp->offset = (u64)OFFSET_MAX; if (argp->offset + argp->count > (u64)OFFSET_MAX)