From patchwork Wed Oct 19 08:23:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5226 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp265929wrs; Wed, 19 Oct 2022 04:23:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM75dRREYiaQMXWoMMZjYwfhSq6dpVYcDu1+OG6o5hwDuTRJPdI9q6JhujfY4MXhj8QZW/Gh X-Received: by 2002:a17:90b:78e:b0:205:c9ae:21f9 with SMTP id l14-20020a17090b078e00b00205c9ae21f9mr9329175pjz.112.1666178610043; Wed, 19 Oct 2022 04:23:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666178610; cv=none; d=google.com; s=arc-20160816; b=J3zfk/gc+srbsjyC/294GsgOMv75xFZZU8CYVpiW8yI1td6ONXyN4SUZpytS+exdZb SIK9w7JjZqclUcVX+v4zmnKR6FFpBL8Pga6Nfhz+SUl+rXBe0oKrl4cvf061FzZ7uFRh IiCaea4CqWcpcvmlbrL9aAOxhlgej8kRIU55ipQ/BOd+R2NBKsPgtJhRhdKX2gsPmCgz WoAGR+cHSBQE45jI6d1Use45ZfItzwoURMET+jnlVucmfiTgFVkl6/k7s0HjdB7iIg/K akK+XmTl4FNe0s3yRFC8Q+w3omabkI2EjQ7cEphc/x4Gs6ZhfFUA24MsmB1722Arc/hJ jIkg== 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:subject:cc:to :from:dkim-signature; bh=jK+dQAgJtjnkuhHU5PsG4dq/cbNUp6IrYyxd5ybFMKg=; b=rrNslOzCkj5ypfq0JsLnPI4TVof0bEjW+2gnpr+uhuMU/W8BNSoFEnUukrHT77Exrr qF9ZNDZlVWBT1XF6/Iy5mKaSEVhLo07szHDmc0uC1/aSqOaqmPGjyWGw1JG/EMtg2AA0 Qj3NvuJ9cQYg5JdZdc3KZzZTgshDmmXGYyYIZS15M/cUgKxE81kPZeYcOulnkSln7suv ZuueVljXI/R76tIbeX+NvtyoiNJnWabZAxUwKiKUf/CwkHzdQhog05EVxd8MTA+VFlH5 uKYNhRzeQvqzDDzZExY4h9uIx1gP74tJRX4L5RXK6to7jIZe8wca7VfpRaCZ/LnLIGVd ucVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=c9AgSY9g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y23-20020a17090aa41700b0020ae29877besi15951094pjp.20.2022.10.19.04.23.13; Wed, 19 Oct 2022 04:23:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=c9AgSY9g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229648AbiJSLMR (ORCPT + 99 others); Wed, 19 Oct 2022 07:12:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232869AbiJSLLR (ORCPT ); Wed, 19 Oct 2022 07:11:17 -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 CE90C15383F; Wed, 19 Oct 2022 03:38:53 -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 C519DB822E0; Wed, 19 Oct 2022 08:42:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C2E3C433D6; Wed, 19 Oct 2022 08:42:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666168923; bh=3fmz19ziBoeqOLteTXpvy4wRMaFIWZi67aTh2vCakBE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c9AgSY9gAKiqr3BN6qRQyfK9KKonGIJxeyqcI0WdURpBK1fbUnuVB06TlC/lGiQ9m 9E4syEfPHGNycXF/4VAzIELsfdOMwVhsZXIVY0NLGWdM/hSvQPrw+7BXzRkjAp44cI IXZIyBwNiupiDDe+ubIAWFuBZFoRO64HoVmHTq6g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chuck Lever , Jeff Layton Subject: [PATCH 6.0 098/862] NFSD: Protect against send buffer overflow in NFSv3 READ Date: Wed, 19 Oct 2022 10:23:05 +0200 Message-Id: <20221019083254.250027544@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747114901975983740?= X-GMAIL-MSGID: =?utf-8?q?1747114901975983740?= From: Chuck Lever commit fa6be9cc6e80ec79892ddf08a8c10cabab9baf38 upstream. 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 Reviewed-by: Jeff Layton Signed-off-by: Chuck Lever Signed-off-by: Greg Kroah-Hartman --- fs/nfsd/nfs3proc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- 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)