From patchwork Wed Oct 19 08:25:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4609 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp211646wrs; Wed, 19 Oct 2022 02:05:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4GtNy8H0hyUSj5dryQWelXoKrOqppGAOOt2tlSfWaBjyyvtS+aa4EWgsox0v+5XUJnAFbB X-Received: by 2002:a63:fd57:0:b0:43c:9a42:74fb with SMTP id m23-20020a63fd57000000b0043c9a4274fbmr6359323pgj.174.1666170329718; Wed, 19 Oct 2022 02:05:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666170329; cv=none; d=google.com; s=arc-20160816; b=uaeLIHDLuDFQ5yECROJ7P7W9FqvqGGNp4YT12xCXXLq2RL9sly/7TYEIOsq4N2979r dMNk31uEpV/TdQbv6Z9eVPK/0xxnXcwLYHLDCMkV7saBoYNAfTRBCKrgLzT0iZeqFg4D aFWwqJ7gtaYuG/zKwUWK42k/9AN+PpxvHF/jKneSD+DhPYpCCOVQZnaQAhB2DVj0Akep NF8Eg7Ne3kBI4WjNkHe8kSa+06kcipATK/rOxS4rTgV0Bex+Eo+egYUtak+yYmCHWs6A TqQBkhNXOVoNW09h72l/plbVrmAX3Z1IsSRkwnWNvBoE/3BtZCYqIhZcVjV3FfoelVFk mZGQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jc19-20020a17090325d300b001811c58029asi16004794plb.434.2022.10.19.02.05.09; Wed, 19 Oct 2022 02:05:29 -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 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?1747106219949088603?= X-GMAIL-MSGID: =?utf-8?q?1747106219949088603?= 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++;