[nfs-utils PATCH v3 3/3] nfsd: fix version sanity check

Scott Mayhew
2025-01-13T23:13:26Z

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