From patchwork Sat Oct 22 07:19:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7832 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1150010wrr; Sat, 22 Oct 2022 03:56:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6hflgA+oWBgaoVhTnIjD0AeOqJCAuGwsqrepY5YJfHUwBTqX6khiXewTqVPQeDR4JYXGwW X-Received: by 2002:a17:907:1b24:b0:76d:7b9d:2f8b with SMTP id mp36-20020a1709071b2400b0076d7b9d2f8bmr18537339ejc.414.1666436187237; Sat, 22 Oct 2022 03:56:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666436187; cv=none; d=google.com; s=arc-20160816; b=weFjLsO8Zko4KVT/mZr0AAxUPotg0+mU5TKx+3WVBfl3KFn3ez8OiMl5t2prVF6Wny ahEnZpZSjccWxdRIrt6802lM/M6Dc7jSRNQMdlvmoNE59s6HDZkWd1L9uFzjkLilOy22 QN37iVwiP60vkigyq0ZLvgdMmyOoN5i9ZNS25yFoYVkMFgJPhux3raBGKf+gqrTLoYbI oeSr1lTGXyff+hAr3O75W2D2GFTuQffyG6upHdonOTbHDM6xrC6iek8R+I+V2uScs27I ZpzfyX9jkM/dt4+voJUbry17R0JtXmkIkIXuFT4mBdrH3wL3J10LRbEagLFZOEYOk1hC 85hw== 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 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.01; Sat, 22 Oct 2022 03:56:27 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747384991632747649?= X-GMAIL-MSGID: =?utf-8?q?1747384991632747649?= 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)