Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3879866rwi; Sat, 22 Oct 2022 01:27:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4yM1QVn+QK2dqc65TN3Z6JlR4pE0Cys5cRJBb6AqMiFjZMJEI4IIMxqTdZqhUql6lITG3B X-Received: by 2002:a17:907:a0e:b0:780:72bb:5ce4 with SMTP id bb14-20020a1709070a0e00b0078072bb5ce4mr19276215ejc.234.1666427235151; Sat, 22 Oct 2022 01:27:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666427235; cv=none; d=google.com; s=arc-20160816; b=rUtkjkWTXvBpOFsag1+/oOxrFGi0U5UteVtD/2PWOZadDFIJoaZwvZfnQSuGIXsT06 ao73lr1+pBaoRzyvACEo/XXJiz0diejzh583khAeW/IcYTBCUSiyrVlSZ5WgNd2u086Z YO7mG5KpREcIS0Kfuk4WJvlxq3wY+1lZJ+u0OB6n9pzdHdVM0aPTRWPypQTS+wRep5gu 2xAQ4PUAafCZmqdp5MraqnA0WFh1L7XWHzH1DVGlK+eDITsHICbiycX2p7//iGl4FvRD JLdAAuQ5tIIEWDcIFlw3E9nst2fxpiCwYGQuRdZJS/MhGkaoafVezG1myE1RE63sIAP7 oYWw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j26-20020a170906255a00b0078de8494d15si2468459ejb.996.2022.10.22.01.26.48; Sat, 22 Oct 2022 01:27:15 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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;