From patchwork Sat Oct 22 07:21:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7292 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1092789wrr; Sat, 22 Oct 2022 00:55:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7sHPUczsI8F5ykWSDo/f1pdXl8F4IGkNM/EhibkyH2dxhTuReMNhZ7bEu89gy6QV9ZINqv X-Received: by 2002:a17:90a:4607:b0:202:e22d:489c with SMTP id w7-20020a17090a460700b00202e22d489cmr63673314pjg.80.1666425316062; Sat, 22 Oct 2022 00:55:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666425316; cv=none; d=google.com; s=arc-20160816; b=leZfia5v+08RRCqtv3HRcNcj/q3CJLo6Jq+zLirhc9qmvLS5YRBblHOLHeZxQXbKSF zA7UCNyV4g4ffyujNrPmIQ+Ayw0d9caSTQB7pse+ARhurTCqaO8s0eN/tsM3hHifQ/uw cFrx5hCv1MC+vox1fo8NF9kQ38ouGu262ZWGhz2t4mAd0Fz+k4sXFwuZlkS6rtV+lMma dnOEAtM/6mdN/tgEhUPnHGWuKwIazXnmv2aFOVyV0lDZzYswZRs5w83npsLjBj6IfjK6 yb5vy5LUwZwmtWrBk7/LHnOuMl6ZUI11jHn+WbbrGMo/+nVOmv1iv9Qsl9xukm6tKPdD pXOQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i63-20020a638742000000b0044034f2c3b8si24715573pge.310.2022.10.22.00.55.03; Sat, 22 Oct 2022 00:55:16 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747373592103222315?= X-GMAIL-MSGID: =?utf-8?q?1747373592103222315?= 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++;