From patchwork Sat Oct 22 07:19:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7209 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1090260wrr; Sat, 22 Oct 2022 00:46:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM56X6erDJ6Q8+FlEcINE0da16yy9X0jE4DT5ONzsCkssrZR/hOVtgVRl/6zvV/HG5hlkeSA X-Received: by 2002:a17:90a:5e04:b0:20b:1f20:5069 with SMTP id w4-20020a17090a5e0400b0020b1f205069mr60518892pjf.126.1666424767597; Sat, 22 Oct 2022 00:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666424767; cv=none; d=google.com; s=arc-20160816; b=CadysKycPcOGPeLlc0edgMEBaSwo39XvwJN/CsAKOAqmQnGtqTi4M6JjAKOP7gpT18 cIl16O9GSPtQFO697qv5tdWiI3y0Zy/zXGIC0qogJSWZTn4fyVA/4GMzFcJbaYyzCaCk k9DBc8UdjngRTA7f4y+bder2U5Z3toO4Y0w/4sOPLBvdlXeVVwSdt1nuoaEmRhtpAKvk EpC8XnetX6n9/NFloS2aHQP72B/WnuOYuuHSOxtmuonpyGnvJV+kvAgTa/uDozWHYHu6 r8JMyuv6M0bn1QS005/1f5GOfyPf5gqQqNt+kUOEuXgIUGOi3Pxe5eM6Q2Be/FsXpkWg e37g== 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=cqqhAVY5XnobQzNjuE/ei5PeH3LehoS0nfzqcPccOUw=; b=OkflGyc04aOxAiulgmvVlCMrNQA3MEhWTG6P7UbVBBs7012T+VHWwkFEzDA7bWI9pb PrnBjPsIDTliaT1v5TaXD+MY58GzArzh/3poWLWKJUfOGfMo27KuFZJBq2rdnX7jl8Pe EBKBxPTqsav8d2trUsOa0OBKj4k7p5eJ3MQ75IDBb62hGWHx7NIrBRR6pAgK6ZZS5zks OCLTomJ2j995zRoDvrjihAe0E+A4kk90QY7G/CRu/gQxRBhx1zxf+gK9HNCkRFiJ5Jk5 8/t+ADqhHimHvOtqu/oYBsLNbxgfo7vNJEAQWS13MeqGIPUM4KYIUS/eFwni77uculLh xmqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=imByZEzX; 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 y4-20020a63ad44000000b0043cb5d08908si28678676pgo.138.2022.10.22.00.45.53; Sat, 22 Oct 2022 00:46:07 -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=imByZEzX; 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 S231307AbiJVHpX (ORCPT + 99 others); Sat, 22 Oct 2022 03:45:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231281AbiJVHnb (ORCPT ); Sat, 22 Oct 2022 03:43:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EF841EF054; Sat, 22 Oct 2022 00:42:19 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 6A04760B09; Sat, 22 Oct 2022 07:38:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 591BEC433C1; Sat, 22 Oct 2022 07:38:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424280; bh=SemBgwVN8OON6vFrEY8Oc1HWbiubQeH0TdHVV1OIaQw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=imByZEzX/uc/3YMDZKdCaRpvA3Lwd8JGKVlgXlayi8ZhbRjam6ACdXKonbSHrDMyW XlYEu/63i4JOc1qPQaoyuyZGtqHn2s7kVDXtqqH4pgdstRPS6iXo4IOSLIFSulwsxO AIrNnP4N0u2a8Sq3/tgISlwywJgkb/VXmqYCn8dc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chuck Lever , Jeff Layton Subject: [PATCH 5.19 087/717] NFSD: Protect against send buffer overflow in NFSv2 READ Date: Sat, 22 Oct 2022 09:19:26 +0200 Message-Id: <20221022072430.760983577@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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?1747373017195409888?= X-GMAIL-MSGID: =?utf-8?q?1747373017195409888?= 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 @@ -182,6 +182,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;