Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp613470pxb; Thu, 30 Sep 2021 13:07:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZMWne5GWEEs3uu/0w+2LaWkYqhnSaKe1j1nBnlmLYRBpJyQUe0GNNkR3SJbv6vJ3GUwGq X-Received: by 2002:a17:907:a411:: with SMTP id sg17mr1410078ejc.412.1633032460229; Thu, 30 Sep 2021 13:07:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633032460; cv=none; d=google.com; s=arc-20160816; b=KFydqcAwkQnSS0TFsoX8BVKRqmZKTM4xCRBZpTSeyyuytnvPrU7zONctoGDfjIRdU8 czN5sVCqIyNsrLmAVzWIpse89l0klgs3O1GPkHtmbhO0TcCLeh5JRwtlOvgDhUys51vw ngE4p0YHucNgBL9AWcXrsTQPqRSOx2WyBrhEIfXnvn9RzxmCR0u7dOesIGVPxhoBfbKA l52v3JPPh/BnLXlhcC/eYMIDgJlEBNrpoGMpt4aBGEn6R1ipJmAwIqaJC/+MuVXQ78nS KeIb9oLKZ4HqH6LKU3QcpMIyGkU4+WDzOjIJoQ7iWPEg7qgFBn6KJUrOmsa0O8uOHedR /4uw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=FhB7zHAh5IAovR7QkUOjhKw1IrI2W5u0C9xqDAyhLVU=; b=rkPRC8TZi3qN4v1CgpIR5xcb7LtD9vGD2W4LvJXAw71VhsdEsPH0Nh5GpwHznXv+Q1 /AIaAFRDyNll0rlyx49U0lDGUvGYsZxv83hMq+3W9g7D1eZhVcLD0ytU18E1yXe65hWH Ua4yfq7j+Jk+bkuM1Hp4d+LEIaDYT/UjY9LHEboUhzmAthDzDWOa6VJV6OYyj/oKtQAE jGPLPKVr3sDJHsOufDC277+urQfJMgshKoysVa9A7Tub+P7zJrNEuh3PYr/ISAjSU9lI Y/UyRJLe/RF8KDlhBILvqpvRIO1TPzqMOarpkNWwdaLUBhLTvQUD14ZTxpMYHkMwXWjM MItg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d7w0qNQ4; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n1si4641735edf.201.2021.09.30.13.07.15; Thu, 30 Sep 2021 13:07:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-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=@kernel.org header.s=k20201202 header.b=d7w0qNQ4; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346118AbhI3Tqc (ORCPT + 99 others); Thu, 30 Sep 2021 15:46:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:58428 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231637AbhI3Tq0 (ORCPT ); Thu, 30 Sep 2021 15:46:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6376B619E7; Thu, 30 Sep 2021 19:44:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633031083; bh=vbndCvgxr5inIoF1r22kWoImjoNLqs4shUtFiY+30Ck=; h=From:To:Cc:Subject:Date:From; b=d7w0qNQ408s3OOfYsvKekRAmCQkAiJRvWuULggRtbszcPSJlbSbFWfU4q+byajlBD c1Imch3OHD7OuslyoxciSclMa2JCa8/68fqMFkdm9TsrwAI4geTEq73MuY1DlTaJXx Ui4UjRuWNwEeqqGWBpoByZeaOb+OV3V9HDZrmaw6VTnfLZO5KA80baYGMRADYfDWX9 IRC+EJY1UaNa429SSdXfQFdMYMPRtU6eShl1j7kCBUdsPq5Ftb5nXnBVVZrZ7kGSVQ sAmeaIa7PgegqBvNEaNVxoTQ8LShFKsMtzwKohTO0MatqASc2kp28b0iUJAdFHhUAu sR1X5fo6EdMQw== From: trondmy@kernel.org To: "J. Bruce Fields" , Chuck Lever Cc: linux-nfs@vger.kernel.org Subject: [PATCH 1/2] nfsd4: Handle the NFSv4 READDIR 'dircount' hint being zero Date: Thu, 30 Sep 2021 15:44:41 -0400 Message-Id: <20210930194442.249907-1-trondmy@kernel.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust 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 --- fs/nfsd/nfs4xdr.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 7abeccb975b2..cf030ebe2827 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -3544,15 +3544,18 @@ nfsd4_encode_dirent(void *ccdv, const char *name, int namlen, 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: -- 2.31.1