Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp803172rwi; Wed, 19 Oct 2022 03:12:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5JexLAYTmfK7icH+Ga1tzt4e+mwTB9SRyqRKx3lDEWahTHMtK9gSaSrW8cTGMBG9aljRpJ X-Received: by 2002:a05:6a00:1707:b0:566:15a1:8b07 with SMTP id h7-20020a056a00170700b0056615a18b07mr7652673pfc.34.1666174369395; Wed, 19 Oct 2022 03:12:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666174369; cv=none; d=google.com; s=arc-20160816; b=lC5GxpppZa+MqjLjZ5LUm9gh3B7FdEp2urja2l22Pu4HNPQ8VHZhONeJWmIsg5MenM pP1cTTNV96fNohvbCcd+iknkZgSI+QidFJ7Bv9BNMUpF8RHkDpJhlvYCscIK8zo0wSzI AG6MGJHwVKNdzTsfwajSco8Ed2lMFNbao9V+5SZcCPCGMi7qVyZvll6NCD+rH948eYK7 U2byAzUSJnVfXguEvSI60z3V9Z5QqFNd6TfiY7FH5E7ucU5zeL7KLd7+wXRvLMUPaTGS UM40kiGVXdAAd5gX+x4y+1ZxiUrep6RU3ajMmCgX+fAaIgvPnxXeBp3pmiSF2nSSAyKG dMMg== 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=/OnIr3GjfgI4eIL1mK3Isags7p1hkrqZwGUoy62ZuyM=; b=hNumEtnMTC0MFiulJk4uOvt4fwyDsoCGfzq31WktppR4KAd07Tqyo5eZRIjSmf1rQc 16nc1/wsfqlZIkXoMpgMWi4OjYkRXXeqSXHCXklxXxmdJGYvHrQSzF9B3cDfczj3To9n FDzfnnJRgcl+4DmPwv7CMtuOHfkosoDvjlyWBOAilI8BS4lBsC1eVNqPb/UFRu1YBCXH QcfK6JHBgQNl4PnmQHqjhBgX6gt8ddA0mE1UPCJJU8V035GpgdtLDM12EUY513OOiayo mjsgTlZxXc2Bso1GMucHy0otBUE7WEZihb7p6DQqdjL4qM1dSp4Dw7FiLO21AC+gTydl qWbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FcPhd3Df; 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 f124-20020a636a82000000b00458a4779f56si18062229pgc.558.2022.10.19.03.12.36; Wed, 19 Oct 2022 03:12:49 -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=FcPhd3Df; 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 S231744AbiJSIwv (ORCPT + 99 others); Wed, 19 Oct 2022 04:52:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231782AbiJSIwO (ORCPT ); Wed, 19 Oct 2022 04:52:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F1455926B; Wed, 19 Oct 2022 01:50:01 -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 95F2E61831; Wed, 19 Oct 2022 08:48:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A91D2C433D6; Wed, 19 Oct 2022 08:48:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169297; bh=gxtBNvdGmC3q4uYGpTMNCsXLCpfFaT+/XRIRyBojW4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FcPhd3Df0+h627L1mFlGr0TJv+lz12asEPSOUR9srBuzvKh+2nGGNBeWFqy6DVES4 bPpv84gxnWpGTGvutURdte2DziZ9qB3Li11OpfZpeE1OvAZDUlg7jEaBe/G18Ow9lo OpRQaVU+adlbGTtIA7S44mdtFGfccHbwbkOHxGR0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chuck Lever , Jeff Layton , Sasha Levin Subject: [PATCH 6.0 224/862] NFSD: Protect against send buffer overflow in NFSv2 READDIR Date: Wed, 19 Oct 2022 10:25:11 +0200 Message-Id: <20221019083259.940007979@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 [ Upstream commit 00b4492686e0497fdb924a9d4c8f6f99377e176c ] Restore the previous limit on the @count argument to prevent a buffer overflow attack. Fixes: 53b1119a6e50 ("NFSD: Fix READDIR buffer overflow") Signed-off-by: Chuck Lever Reviewed-by: Jeff Layton Signed-off-by: Chuck Lever Signed-off-by: Sasha Levin --- fs/nfsd/nfsproc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/nfsproc.c b/fs/nfsd/nfsproc.c index fcbf7e4083af..4b19cc727ea5 100644 --- a/fs/nfsd/nfsproc.c +++ b/fs/nfsd/nfsproc.c @@ -568,12 +568,11 @@ static void nfsd_init_dirlist_pages(struct svc_rqst *rqstp, struct xdr_buf *buf = &resp->dirlist; struct xdr_stream *xdr = &resp->xdr; - count = clamp(count, (u32)(XDR_UNIT * 2), svc_max_payload(rqstp)); - memset(buf, 0, sizeof(*buf)); /* Reserve room for the NULL ptr & eof flag (-2 words) */ - buf->buflen = count - XDR_UNIT * 2; + buf->buflen = clamp(count, (u32)(XDR_UNIT * 2), (u32)PAGE_SIZE); + buf->buflen -= XDR_UNIT * 2; buf->pages = rqstp->rq_next_page; rqstp->rq_next_page++; -- 2.35.1