Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp890352rwi; Wed, 19 Oct 2022 04:22:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5OEAiHdFdGvZfs9nO5nqc0h1/UW2468bH3mDJFA2HBK7rFpiLPA54XDuj18PTTFfC06RoA X-Received: by 2002:a05:6a00:a22:b0:54e:6a90:fbef with SMTP id p34-20020a056a000a2200b0054e6a90fbefmr8139543pfh.53.1666178555033; Wed, 19 Oct 2022 04:22:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666178555; cv=none; d=google.com; s=arc-20160816; b=ChHs0uP0gBnBfDDxwYg2yyYipt/hd9OoTMT2m7v+K/wonV8/ImhCi1UbisnG7QBSJQ HeVCDab82KDwm2Hs8w2bgVaeXpJ4iGmbN86+sr/C7Iq0N8KC0FdDBM2i6mLLAfrFaAP6 eN6vyiAFOQcsvbZf0BzXA+zh1j9dFh8Smqn95e18CssEF2DJsBY9gk3itCSfNlSYje1+ /sBUi6bcQF8kq4N/qdt7nZJW73Q+m/yW0AdcJlRgXxeTlqo0/N48UaAjnsYVYE0DtHqn cwV6RVNUA5rZjK8D3NbcwPvTQhBXECRm3g98zKhfdnJiK9dbh3NAYosCKcc5HJvEgPHI ALSA== 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 Return-Path: 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.22.15; Wed, 19 Oct 2022 04:22:35 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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;