Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1615094pxb; Mon, 11 Oct 2021 09:31:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtX4kNdp9lGzTvfzJupAGBZeRoCY54rxJlN6HV3J/5+Cm4Yz2zG1YL6OYUEZzv3+9bbMyS X-Received: by 2002:a17:907:7b8d:: with SMTP id ne13mr10450977ejc.269.1633969914821; Mon, 11 Oct 2021 09:31:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633969914; cv=none; d=google.com; s=arc-20160816; b=LgvEpdVTKS7jc+aRwZMvZoOQgnAlTDb/CHMgj53JZ992EYdTcktvbogrqGiW5dVOGX Fb0wB5S8+wdTFL6UJBlQeK34HzarM26yIw34uzC0CybnXvpBz9m7+0y6ps9IJuFlwuHO 02m4sT6TTnY31UZZljkO20FdJxQGDQ7Dm8dltYoy3JiwA/UakFAsXEN0+BHDNGHKxbhh zMi5i9b+Kka1B9DytV/gRCEZzUWRtwHhXOGgBeghmHvLizwGCObHxWSJjb7y0/FN04NP LK9SQapoWf/Lko7Ux+7oevnsCpgsYfdHkRTXsqNE2qw3u7nEwzTbGQSDoW4nY+kIC52D ExCg== 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=Aqn9U8YnJnrJbhz/BDtUuVFsajGN3T+IXfdzuRXGI2E=; b=kRwy8mpjaziEPAVrBcMkQZWZd5ZIjWS84qpLX8b5rA9CNuphTx0/iAykwp81B3pGbo U2y6d7qLBJTLjxJtrvREP+D+HKLhh8Nr4v9RQXt3pE3HtZBmYjOuISgdBPrVBxzRcT9s 4nOnkUfc8EWU8t+ODW8aUP7WUmSXD6nj0i/rU0W3gdImWlLHichtL+uxvhmVw2l/kela HxDm2OQ76Es+9Zmqcu3wspkd7HmxGkOTr+JQf7p+1JRf0ROcE2yKFth0HBbjTMN19JDq PHIFoLfNxlnO/bpaLQEDH0qjJZQygx/GckFZDqdm18dbmm3WmactL2+5cmASSUfa6v/8 7K+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZpXWBe84; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b14si10969781ejv.295.2021.10.11.09.31.31; Mon, 11 Oct 2021 09:31:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZpXWBe84; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S237517AbhJKNyo (ORCPT + 99 others); Mon, 11 Oct 2021 09:54:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:40464 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237814AbhJKNxN (ORCPT ); Mon, 11 Oct 2021 09:53:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 82313610EA; Mon, 11 Oct 2021 13:51:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633960262; bh=4Mpa3t6d3YPxBVYe91lMhmo3cMoVNduudfA61Q8tzT4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZpXWBe84Ws1wsB0knZ8pQvIkEf4UgiWNjRnN+kmLAD+Mz6emOS5rhyv160Ahpdx+B mz6fjjGoYLu9dPdFzA9NGuQCdeX7WfB8sFYNKRm4TpPM80JkKh5k0oV6G8sEpEQJhf gRC+CV2kXcpt16bmJt7FG4Ey3Tpm/Uu2PRXw8sZU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Trond Myklebust , Chuck Lever Subject: [PATCH 5.10 14/83] nfsd4: Handle the NFSv4 READDIR dircount hint being zero Date: Mon, 11 Oct 2021 15:45:34 +0200 Message-Id: <20211011134508.846916958@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211011134508.362906295@linuxfoundation.org> References: <20211011134508.362906295@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Trond Myklebust commit f2e717d655040d632c9015f19aa4275f8b16e7f2 upstream. RFC3530 notes that the 'dircount' field may be zero, in which case the recommendation is to ignore it, and only enforce the 'maxcount' field. In RFC5661, this recommendation to ignore a zero valued field becomes a requirement. Fixes: aee377644146 ("nfsd4: fix rd_dircount enforcement") Cc: Signed-off-by: Trond Myklebust Signed-off-by: Chuck Lever Signed-off-by: Greg Kroah-Hartman --- fs/nfsd/nfs4xdr.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -3427,15 +3427,18 @@ nfsd4_encode_dirent(void *ccdv, const ch goto fail; cd->rd_maxcount -= entry_bytes; /* - * RFC 3530 14.2.24 describes rd_dircount as only a "hint", so - * let's always let through the first entry, at least: + * RFC 3530 14.2.24 describes rd_dircount as only a "hint", and + * notes that it could be zero. If it is zero, then the server + * should enforce only the rd_maxcount value. */ - if (!cd->rd_dircount) - goto fail; - name_and_cookie = 4 + 4 * XDR_QUADLEN(namlen) + 8; - if (name_and_cookie > cd->rd_dircount && cd->cookie_offset) - goto fail; - cd->rd_dircount -= min(cd->rd_dircount, name_and_cookie); + if (cd->rd_dircount) { + name_and_cookie = 4 + 4 * XDR_QUADLEN(namlen) + 8; + if (name_and_cookie > cd->rd_dircount && cd->cookie_offset) + goto fail; + cd->rd_dircount -= min(cd->rd_dircount, name_and_cookie); + if (!cd->rd_dircount) + cd->rd_maxcount = 0; + } cd->cookie_offset = cookie_offset; skip_entry: