From nobody Fri Dec 19 19:14:27 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF63FECAAA1 for ; Mon, 24 Oct 2022 14:03:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233537AbiJXODc (ORCPT ); Mon, 24 Oct 2022 10:03:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236947AbiJXOCV (ORCPT ); Mon, 24 Oct 2022 10:02:21 -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 42B0DC06BC; Mon, 24 Oct 2022 05:48:25 -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 7008F612A8; Mon, 24 Oct 2022 12:37:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85058C433D7; Mon, 24 Oct 2022 12:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666615025; bh=lr5RdlAhobTk+e9B5M/hxDb1QkDztCkQ2R41RQeU1oo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e1HpM3kD3fJJDtmWjoWgeab3zC5gBnWAmYGt7IjGMW6oDSEGs4fnZU4eZvnUM6Jw2 6rMwXvuYa0RxiYbJcxoZih6qw5Nx3laI2Q7kZHvy3A2pm1WctWqzP8VZLfajr9sgwQ /anGmvf3CCISm9m6AsEsE7Ez0MUkumfjcNN7mdIM= 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.15 066/530] NFSD: Protect against send buffer overflow in NFSv3 READ Date: Mon, 24 Oct 2022 13:26:50 +0200 Message-Id: <20221024113048.017595942@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Chuck Lever commit fa6be9cc6e80ec79892ddf08a8c10cabab9baf38 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/nfs3proc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/fs/nfsd/nfs3proc.c +++ b/fs/nfsd/nfs3proc.c @@ -146,7 +146,6 @@ nfsd3_proc_read(struct svc_rqst *rqstp) { struct nfsd3_readargs *argp =3D rqstp->rq_argp; struct nfsd3_readres *resp =3D rqstp->rq_resp; - u32 max_blocksize =3D svc_max_payload(rqstp); unsigned int len; int v; =20 @@ -155,7 +154,8 @@ nfsd3_proc_read(struct svc_rqst *rqstp) (unsigned long) argp->count, (unsigned long long) argp->offset); =20 - argp->count =3D min_t(u32, argp->count, max_blocksize); + argp->count =3D min_t(u32, argp->count, svc_max_payload(rqstp)); + argp->count =3D min_t(u32, argp->count, rqstp->rq_res.buflen); if (argp->offset > (u64)OFFSET_MAX) argp->offset =3D (u64)OFFSET_MAX; if (argp->offset + argp->count > (u64)OFFSET_MAX)