From patchwork Wed Oct 19 08:23:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5219 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp265268wrs; Wed, 19 Oct 2022 04:22:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4X7LFVBMk82BI4IM4RZlY0gQW+L93ISFW40sdyS3fnh2WDDCvONto0mSeohAjh2TuimWRw X-Received: by 2002:a05:6a00:1c99:b0:562:6292:9e4e with SMTP id y25-20020a056a001c9900b0056262929e4emr8237270pfw.22.1666178520971; Wed, 19 Oct 2022 04:22:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666178520; cv=none; d=google.com; s=arc-20160816; b=ydUzlPx9MLb73fWgH6wFlzPBIBSNWrOzuWhiEa4kTyAOVAWxNkNa9jYWveit0cCvL8 Psm5f7kalvrc48hTauyg3auy3+GxfTsZPz/Hii5rH7WIpvon7RGZu+68LM6fL7+VatP5 PQAJKKIkZkhG/FaTPeVNegvK5Vzc5GKIiKDH8srL4QffnKT42lCMmT4nNRnv5hEmFQ0p eBBvQMuR5I9K9kbszk+V5PZWu/qeW8XIzqFfcVFV3VIB0fbmdxMqhcSXP+2Uwhy5beuD u+NJim0/lx+8fZlQWktWxsZQMTQWbVX0y35HBUKfMtB6mTh7/bMojhkL003DvD7g1aAg EP1A== 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=mqWq54k46wPizfmcGtuziCCPlOuS8vQO6RBAw/89XXM=; b=tMJby+AAVrlqw9HygiZW7s3kDlifTHRZleKwS/nhuBtukF6PJ53eUOzmYKI9N9MkKa /IlfI9BkpS2TKgpirrUEWzBJ1iabf+oDsGxq2XLWahEvodQPBL94pVFpC6zpplXZSnnO o6nny0PxAgxhJw7Y2tQ/L5F97go53YpOKKNw5bjqop7uQB8E+7GlYwXVe4Wm8l/oouHg FBI6rTkzZUEr1cpx4/6RxnGwd0eNh1XELU5m/b+/h1LMFeL5X8y6mLFBQDzyScLZjVi8 oQ9pSI3p90RXr+L8d7Mc9rPQkO9Rvx3i9jMMWp42nzE1BfrIsDQ8KnEzErxL3cRhagYU xesQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=L2tVfxXx; 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 lr1-20020a17090b4b8100b002034e5450f0si26925324pjb.131.2022.10.19.04.21.45; Wed, 19 Oct 2022 04:22:00 -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=L2tVfxXx; 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 S231997AbiJSLL5 (ORCPT + 99 others); Wed, 19 Oct 2022 07:11:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231702AbiJSLKy (ORCPT ); Wed, 19 Oct 2022 07:10:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16643108DC1; Wed, 19 Oct 2022 03:38:29 -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 685DCB822DA; Wed, 19 Oct 2022 08:41:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D753CC433D6; Wed, 19 Oct 2022 08:41:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666168916; bh=3kmaUKiFlPfcYVCduoERC7tchXK2w82pKHJ6gYQ0xiE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L2tVfxXxC3MY2oYxHVsJg4p4Wq4vjHJT4giN7J1BNfoRxwLIKdTClVppdSaIWny0F aI6rq4SxbWycJzcLzsQITvt1uHxD4ACE6C3m2/wU41uo9kBXTFhxlO6svxhWAHjPUY mdelNiGzEqizdVEdLDcFqRVKifJ2uDTsnX1KGeSA= 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 097/862] NFSD: Protect against send buffer overflow in NFSv2 READ Date: Wed, 19 Oct 2022 10:23:04 +0200 Message-Id: <20221019083254.216282279@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?1747114808726504096?= X-GMAIL-MSGID: =?utf-8?q?1747114808726504096?= From: Chuck Lever commit 401bc1f90874280a80b93f23be33a0e7e2d1f912 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/nfsproc.c | 1 + 1 file changed, 1 insertion(+) --- a/fs/nfsd/nfsproc.c +++ b/fs/nfsd/nfsproc.c @@ -185,6 +185,7 @@ nfsd_proc_read(struct svc_rqst *rqstp) argp->count, argp->offset); argp->count = min_t(u32, argp->count, NFSSVC_MAXBLKSIZE_V2); + argp->count = min_t(u32, argp->count, rqstp->rq_res.buflen); v = 0; len = argp->count;