Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp4016555rwi; Sat, 22 Oct 2022 03:57:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM44NGG2Kj9BsRzWCdSpdi85HU7p1AhLDe+jJKIMAX1Zkoee7YxBSkkFF4pfP8yq6BEhJ3az X-Received: by 2002:a05:6402:254d:b0:45d:3ed3:8aa9 with SMTP id l13-20020a056402254d00b0045d3ed38aa9mr21227582edb.157.1666436239119; Sat, 22 Oct 2022 03:57:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666436239; cv=none; d=google.com; s=arc-20160816; b=HOuiUSNONoL0iDNB301dholqZJMXiZnScQ+B959s83S0EERG8A2bIJ45y3FV2MSSDg LHHAXwZnC/wwTpqW7LMLeMebQmZrt/+ZxFgYw0/6SH3XkehVi+GSXK96m2G1z0d3vLfM 7x4iSCyYazyA8rZ82L+0MHemOjGgE1DTrN4GFNInywdfKhBFr5Vy5h53zRF+xWQvAbSZ IT6LQswfr+sS3ayOVv9JfXuTNYW2yrY4mj5rt2TNjs9c2Kd0WJqOIOiqA30TyPU0Bv9c a+Pq+zLtshTrrXAr2lXc4oOLSNHZFbsLUFl2WEYQC7v2pq7BhVy6kk1tfjTT6HUAW8hK +AgQ== 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=sEXeLXM5zo1sRs80lMyeuLBf7pTPyn2dfyEJ0npXIy8=; b=fXCQm0Pq5TDc2kPuEwQOQj/+XWkNc2Gfua/RHCgvo02kdDLr17GK9XhmJessRjChrs M03XdURrwikMg8LPmeNKITVxQL7NqFm0qZpy83qKHb8VOTeJwiml7SjxD9uPAkuSo1SX xFsBhA78/B8SDMTiashlB1cEn6mq/4rkmIbxn0fIF+CIuaC7Z9UjH2DukQWa7JHSFqC+ a5m5tcKvEbTYHZXNnRVCEpSC816kkcTgxNuRC+VVHeObtDL+FUMJscj9UfewDRH7L7iW +I+YO2hDOcFYQRTcRLTXA+iWauwoahZy/LGdYNReddlzc1RkN05TOatNX8NW2YlaDhV/ dSAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1gxTK2iB; 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 y14-20020aa7ce8e000000b00458f6e66baesi19990052edv.278.2022.10.22.03.56.53; Sat, 22 Oct 2022 03:57:19 -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=1gxTK2iB; 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 S229944AbiJVKqL (ORCPT + 99 others); Sat, 22 Oct 2022 06:46:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230358AbiJVKpl (ORCPT ); Sat, 22 Oct 2022 06:45:41 -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 D8D0529F119; Sat, 22 Oct 2022 03:03:32 -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 220F160B07; Sat, 22 Oct 2022 07:38:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39551C433D6; Sat, 22 Oct 2022 07:38:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424283; bh=vj+c+klnG/XyjchScAUrWaGSDcH9xzhtSiLQpU4pB3k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1gxTK2iBBxRK6m6bbjIBj1oB+R2dIDKOi/kA90rmc0vlhhWlAUcx9El5oD60Hj6TY EhJSWuwTH9gRNXxJFFJzswIY1Foh7lTrxwFFR7yxShsalVr4oQT5ZSTlhAhZG4RKiK w1OGg08CD3qhYxa3bbOUcqKHH1U7969UeuLq6l8M= 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 088/717] NFSD: Protect against send buffer overflow in NFSv3 READ Date: Sat, 22 Oct 2022 09:19:27 +0200 Message-Id: <20221022072430.934420268@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.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 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 @@ -147,7 +147,6 @@ nfsd3_proc_read(struct svc_rqst *rqstp) { struct nfsd3_readargs *argp = rqstp->rq_argp; struct nfsd3_readres *resp = rqstp->rq_resp; - u32 max_blocksize = svc_max_payload(rqstp); unsigned int len; int v; @@ -156,7 +155,8 @@ nfsd3_proc_read(struct svc_rqst *rqstp) (unsigned long) argp->count, (unsigned long long) argp->offset); - argp->count = min_t(u32, argp->count, max_blocksize); + argp->count = min_t(u32, argp->count, svc_max_payload(rqstp)); + argp->count = min_t(u32, argp->count, rqstp->rq_res.buflen); if (argp->offset > (u64)OFFSET_MAX) argp->offset = (u64)OFFSET_MAX; if (argp->offset + argp->count > (u64)OFFSET_MAX)