public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Scott Mayhew <smayhew@redhat.com>
To: steved@redhat.com
Cc: jlayton@kernel.org, yoyang@redhat.com, linux-nfs@vger.kernel.org
Subject: [nfs-utils PATCH v3 3/3] nfsd: fix version sanity check
Date: Mon, 13 Jan 2025 18:13:19 -0500	[thread overview]
Message-ID: <20250113231319.951885-4-smayhew@redhat.com> (raw)
In-Reply-To: <20250113231319.951885-1-smayhew@redhat.com>

rpc.nfsd's version sanity check needs to check both the major and
minor versions before failing with a "no version specified" error.

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
---
 utils/nfsd/nfsd.c | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/utils/nfsd/nfsd.c b/utils/nfsd/nfsd.c
index f787583e..a4056499 100644
--- a/utils/nfsd/nfsd.c
+++ b/utils/nfsd/nfsd.c
@@ -68,7 +68,7 @@ read_nfsd_conf(void)
 int
 main(int argc, char **argv)
 {
-	int	count = NFSD_NPROC, c, i, error = 0, portnum, fd, found_one;
+	int	count = NFSD_NPROC, c, i, j, error = 0, portnum, fd, found_one;
 	char *p, *progname, *port, *rdma_port = NULL;
 	char **haddr = NULL;
 	char *scope = NULL;
@@ -330,11 +330,30 @@ main(int argc, char **argv)
 		exit(1);
 	}
 
-	/* make sure that at least one version is enabled */
+	/*
+	 * Make sure that at least one version is enabled.  Note that we might
+	 * need to check the minorvers bit field twice - first while handling
+	 * major version 4 in versbits, and again if no major verions were
+	 * enabled in versbits.
+	 */
 	found_one = 0;
-	for (c = NFSD_MINVERS; c <= NFSD_MAXVERS; c++) {
-		if (NFSCTL_VERISSET(versbits, c))
-			found_one = 1;
+	for (i = NFSD_MINVERS; i <= NFSD_MAXVERS; i++) {
+		if (NFSCTL_VERISSET(versbits, i)) {
+			if (i == 4) {
+				for (j = NFS4_MINMINOR; j <= NFS4_MAXMINOR; j++) {
+					if (NFSCTL_MINORISSET(minorvers, j))
+						found_one = 1;
+				}
+			} else {
+				found_one = 1;
+			}
+		}
+	}
+	if (!found_one) {
+		for (i = NFS4_MINMINOR; i <= NFS4_MAXMINOR; i++) {
+			if (NFSCTL_MINORISSET(minorvers, i))
+				found_one = 1;
+		}
 	}
 	if (!found_one) {
 		xlog(L_ERROR, "no version specified");
-- 
2.45.2


  parent reply	other threads:[~2025-01-13 23:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-13 23:13 [nfs-utils PATCH v3 0/3] version handling fixes for nfsdctl and rpc.nfsd Scott Mayhew
2025-01-13 23:13 ` [nfs-utils PATCH v3 1/3] nfsdctl: tweak the version subcommand behavior Scott Mayhew
2025-01-13 23:13 ` [nfs-utils PATCH v3 2/3] nfsdctl: tweak the nfs.conf version handling Scott Mayhew
2025-01-13 23:13 ` Scott Mayhew [this message]
2025-01-13 23:20 ` [nfs-utils PATCH v3 0/3] version handling fixes for nfsdctl and rpc.nfsd Scott Mayhew
2025-01-18 12:12   ` Steve Dickson
2025-01-18 12:08 ` Steve Dickson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250113231319.951885-4-smayhew@redhat.com \
    --to=smayhew@redhat.com \
    --cc=jlayton@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=steved@redhat.com \
    --cc=yoyang@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox