Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3884606rwi; Sat, 22 Oct 2022 01:32:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM61pEFqQAha4ShGp0dqnL4fTOr/23XyWMad31ZcsnvGhUPODXeniIctDmYzSqBXxNSqtH26 X-Received: by 2002:a05:6a00:228f:b0:566:6ecd:29d9 with SMTP id f15-20020a056a00228f00b005666ecd29d9mr23818291pfe.62.1666427530185; Sat, 22 Oct 2022 01:32:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666427530; cv=none; d=google.com; s=arc-20160816; b=a869ioMFyi0p+OR7M/MiTgpsnqYVRLZ10+JheVROfwMtQyeY13QONzcd3rbNYWQwYu 6O8L45qKlE9Byio+hZ9S2l0c7FCq6k5AUFUrvBlN6AdIKvQV5qhuBcyH1xMbMEb/p+y4 yhpMy203lpKr/HSHSB/MK0ALV0M+vhfQVsRttzCro57/O8kthV8WZ2MlrfGBXK2kKQRu EdJyC9NrbbEd3wTcgTdgYjTb8ftR+03fIkJwbsahUdfgNHROTb6BeyKa/dpYhIMfs+7Z 7xpB4qFl4FFGJQvvkXO0x4LsJhtWrrYaARGVlsNOSs8RS8SV0+9oPiwz1wCmV6S8ZfAw TVAw== 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=wstaSL58UDwaZKaPtxF4K9ms4zaJOSt6ho2H/Yaoml4=; b=QDmMmOct41p3VZ55UeoqjKxP9AcCT5JM3eEg17hb/c1OdOtoCeqiApuSP4GzjOrXh/ k+abRVndccD7I2vI1sQcXWl0nKeidQ79GrI0SCcTJG9OsQmJmPg4O3t3pwDRs18FCrDv zB5yiaUa24VSdk7RwIE7GJ55QGMa7BBsjsGYCUAOZH6MGJFigl5wVzxXE9CBQDXzw9xC AP8SyezWymBW+iU+to9JzDvtC4oq/bXyDr7jGdDnL8izx7Zpf5hlcmkGEltccUylHo9G Wrj0XrRqe+JURjJ6I9biU+8uw5w8b8hZyApnekBJgm2WJzPFr6dDVlOceACWBMuiCnKm 69/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZzoUd26c; 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 d17-20020a170903209100b00182c500d95bsi22924250plc.1.2022.10.22.01.31.58; Sat, 22 Oct 2022 01:32:10 -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=ZzoUd26c; 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 S232032AbiJVHxm (ORCPT + 99 others); Sat, 22 Oct 2022 03:53:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231893AbiJVHv1 (ORCPT ); Sat, 22 Oct 2022 03:51:27 -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 F3F362C2AF3; Sat, 22 Oct 2022 00:46:26 -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 B8D7460B6B; Sat, 22 Oct 2022 07:43:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0DE4C433D6; Sat, 22 Oct 2022 07:43:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424622; bh=vvroSdVnhpOzWpAlb2Ota3DJevOUQESG8b8NQmA2ZKA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZzoUd26cmmDtzdt4T7fljJZ9Axaag8op/CxXm4TLV3rrkG8JwKpa85FrFOxd6Llj+ 94vbKNXmPfGYiaJmsavaaeaIofQg07Jw3Al0hfareDFz02CwEOKFBUa0UiWWVn8Akx VhKOBYYTTqQGVoRXBszD1CASuhGrjiK9pyiyTQgY= 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 5.19 197/717] NFSD: Protect against send buffer overflow in NFSv2 READDIR Date: Sat, 22 Oct 2022 09:21:16 +0200 Message-Id: <20221022072450.362303294@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.3 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 16cde315f454..f65eba938a57 100644 --- a/fs/nfsd/nfsproc.c +++ b/fs/nfsd/nfsproc.c @@ -557,12 +557,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