Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1979509rwe; Fri, 2 Sep 2022 06:56:11 -0700 (PDT) X-Google-Smtp-Source: AA6agR7S0kynEAm+V6d1f+MUmYJYOrRBzYulavxQ+8rSCQpnaSgZvDKBRb80AEG/jSHNVtS0KIDx X-Received: by 2002:a17:90b:1b48:b0:1f4:f4e5:c189 with SMTP id nv8-20020a17090b1b4800b001f4f4e5c189mr4804771pjb.226.1662126970797; Fri, 02 Sep 2022 06:56:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662126970; cv=none; d=google.com; s=arc-20160816; b=tjvWMVkm3V2vpDQ+eN/XAdKrBmGdYk6FZYLc/SktUbl/HrPe7/PRDteK/a/7ZFAOLy 5j9o1TUHdtdSLphKxCI9QJzWUXt0OnyuYZbn9Yz+wJzQjQuPlKFIY2/X52QUlebYKxo0 RjpEyHWnwUaalCE1MU9ulicwrKDo5Kn51f0UcGUDSyMj1JbWr9/Mtq9pXL/eA0WKwbAw XjJHUKp+3L524KAmxvryK0kMVHZzBEaV4E7DPyOpZcr6gF3fz2tLnWzTJ/foYBtCD2x9 RC4S+DW53CNJtADAKJ5McYmAXVN7ngcwvfcE587Iu58fPSnz7YMTZI44pkCdZhr/Lbxg efSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:to:from :subject:message-id:dkim-signature; bh=CDkEvNLTeInjY8ml//Y1rtppzxhPdharUius04On0zQ=; b=azyou8CKvpl+WiTx7b2GuZ4NEtvqTwKP0zJhU5jG0pRLaQU+3DMnm3JN2sHsa1P90S iKYCdofDTKXu6E/XWwKA6AhN1VzULYYQreoNvDN0DQavPdJ0jjWzNGlI1IslbVUOJv3u zZBDUDD8QwCZVv3KlTvGD65eoVZSKxtNfdGsSEw7d2DpHz1VRh9q74RGTQDSEDFtEM6m G48jdomfOE9kMhzqf8/xzalvknvf48aLz51SlEx3OJOl0dN2TVdYbsztEFODr2Hzm1Zt Wmdj0KZygSvfLqGIyVRubYzg7m29jZd0N3888/SJ6RoaartIJNZe9irzUaWAFecNx8Ke P0sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=W0F1ueBk; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g4-20020a1709026b4400b0016f16417f6dsi1999276plt.16.2022.09.02.06.55.57; Fri, 02 Sep 2022 06:56:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-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=@kernel.org header.s=k20201202 header.b=W0F1ueBk; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237641AbiIBNjj (ORCPT + 99 others); Fri, 2 Sep 2022 09:39:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237888AbiIBNiq (ORCPT ); Fri, 2 Sep 2022 09:38:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF3D7E588C for ; Fri, 2 Sep 2022 06:17:05 -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 528956206B for ; Fri, 2 Sep 2022 13:12:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67B3CC433C1; Fri, 2 Sep 2022 13:12:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662124351; bh=tyYIsIkZY6uSMJKlwRH66HMPiYM7IXhUQ2tYayZxyTM=; h=Subject:From:To:Date:In-Reply-To:References:From; b=W0F1ueBkY1E0A2EDBtCFG/P0afgRlhgVhfQ8UXFgh09bQK5QNbaX3MB60TH1Rv127 k6DHKnaH7IzC/3/UlGBq++wKqdbk1iA3A4nYwFLIaHWS4jv+yLsfCQTDaLYVYwrH+J yVlCw1628szH7tF0d814F72LQBUk2cK+E65Yvc3ADdCezHV7gm5kCwylDVFd8EKq3U GBmPJn3LUog7uW5uxtFIymhfE0RJRCf2UUDacEnYpFFzcgBE4zQAcM/V8NofdZst2S xJsYrCP0olvO7TioVkuUST0S8vPgz3vIUrPlXm2PXCuf9+H/PJ5hd9ArbTqElt5AI9 AQ7ITFEVgke0Q== Message-ID: <3490fa376a463474cec0024798b2ebe25808141f.camel@kernel.org> Subject: Re: [PATCH v3 4/6] NFSD: Protect against send buffer overflow in NFSv3 READDIR From: Jeff Layton To: Chuck Lever , linux-nfs@vger.kernel.org Date: Fri, 02 Sep 2022 09:12:30 -0400 In-Reply-To: <166205941213.1435.18172275008498406790.stgit@manet.1015granger.net> References: <166204973526.1435.6068003336048840051.stgit@manet.1015granger.net> <166205941213.1435.18172275008498406790.stgit@manet.1015granger.net> Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4 (3.44.4-1.fc36) MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 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,T_SCC_BODY_TEXT_LINE 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-nfs@vger.kernel.org On Thu, 2022-09-01 at 15:10 -0400, Chuck Lever wrote: > 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 message at the same time. >=20 > 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. >=20 > 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. >=20 > Thanks to Aleksi Illikainen and Kari Hulkko for uncovering this > issue. >=20 > Reported-by: Ben Ronallo > Cc: > Signed-off-by: Chuck Lever > --- > fs/nfsd/nfs3proc.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) >=20 > diff --git a/fs/nfsd/nfs3proc.c b/fs/nfsd/nfs3proc.c > index a41cca619338..7a159785499a 100644 > --- a/fs/nfsd/nfs3proc.c > +++ b/fs/nfsd/nfs3proc.c > @@ -563,13 +563,14 @@ static void nfsd3_init_dirlist_pages(struct svc_rqs= t *rqstp, > { > struct xdr_buf *buf =3D &resp->dirlist; > struct xdr_stream *xdr =3D &resp->xdr; > - > - count =3D clamp(count, (u32)(XDR_UNIT * 2), svc_max_payload(rqstp)); > + unsigned int sendbuf =3D min_t(unsigned int, rqstp->rq_res.buflen, > + svc_max_payload(rqstp)); > =20 > memset(buf, 0, sizeof(*buf)); > =20 > /* Reserve room for the NULL ptr & eof flag (-2 words) */ > - buf->buflen =3D count - XDR_UNIT * 2; > + buf->buflen =3D clamp(count, (u32)(XDR_UNIT * 2), sendbuf); > + buf->buflen -=3D XDR_UNIT * 2; > buf->pages =3D rqstp->rq_next_page; > rqstp->rq_next_page +=3D (buf->buflen + PAGE_SIZE - 1) >> PAGE_SHIFT; > =20 >=20 >=20 Reviewed-by: Jeff Layton