Skip to contentSkip to conversation

mountd does not check for membership of IP addresses in netgroups if the IP is resolvable

PATCH Frank Sorenson 2 participants 2 messages Oct 22, 2015 – Nov 4, 2015 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

If a netgroup entry specifies an IP address, and that IP address can be resolved to a name, the current match code in mountd only tests whether the canonical name and any aliases are in the netgroup, and does not test whether the IP address is in the netgroup.

(IP addresses which do not resolve to a name are already checked for membership in the netgroup)

The following demonstrates this issue:

/etc/netgroup:
test_netgroup (127.0.0.1,-,-)

/etc/exports:
/data @test_netgroup(rw,sync)

# mkdir /data
# mkdir -p /mnt/test
# exportfs -a
# mount localhost:/data /mnt/test

assuming that there is a localhost entry in /etc/hosts, this will fail:
mount.nfs: access denied by server while mounting localhost:/data

The patch below adds the code to test for the IP addresses in the netgroup, and the mount now succeeds.

Author: Frank Sorenson <[email protected]>
Date:   Thu Oct 22 15:38:17 2015 -0500

mountd: fix netgroup lookup for resolvable IP addresses

If a netgroup entry specifies an IP address, and that IP address can be resolved to a name, mountd will currently only test whether the canonical name and any aliases are in the netgroup, and does not test whether the IP address is in the netgroup (IP addresses which do not resolve to a name are already checked against the netgroup).

This patch adds the check to see whether the IP addresses are in the netgroup.

support/export/client.c +15 -0
index 95156f0..f6c58f2 100644
@@ -686,6 +686,21 @@ check_netgroup(const nfs_client *clp, const struct addrinfo *ai)
 		}
 	}
 
+	/* check whether the IP itself is in the netgroup */
+	for (tmp = ai ; tmp != NULL ; tmp = tmp->ai_next) {
+		free(hname);
+		hname = calloc(INET6_ADDRSTRLEN, 1);
+
+		if (inet_ntop(tmp->ai_family, &(((struct sockaddr_in *)tmp->ai_addr)->sin_addr), hname, INET6_ADDRSTRLEN) != hname) {
+			xlog(D_GENERAL, "  %s: unable to inet_ntop addrinfo %p: %m", __func__, tmp, errno);
+			goto out;
+		}
+		if (innetgr(netgroup, hname, NULL, NULL)) {
+			match = 1;
+			goto out;
+		}
+	}
+
 	/* Okay, strip off the domain (if we have one) */
 	dot = strchr(hname, '.');
 	if (dot == NULL)
#2 lore raw
Quoted 45 lines · Frank Sorenson

If a netgroup entry specifies an IP address, and that IP address can be resolved to a name, the current match code in mountd only tests whether the canonical name and any aliases are in the netgroup, and does not test whether the IP address is in the netgroup.

(IP addresses which do not resolve to a name are already checked for membership in the netgroup)

The following demonstrates this issue:

/etc/netgroup:
test_netgroup (127.0.0.1,-,-)

/etc/exports:
/data @test_netgroup(rw,sync)

# mkdir /data
# mkdir -p /mnt/test
# exportfs -a
# mount localhost:/data /mnt/test

assuming that there is a localhost entry in /etc/hosts, this will fail:
mount.nfs: access denied by server while mounting localhost:/data

The patch below adds the code to test for the IP addresses in the netgroup, and the mount now succeeds.

Author: Frank Sorenson <[email protected]>
Date:   Thu Oct 22 15:38:17 2015 -0500

mountd: fix netgroup lookup for resolvable IP addresses

If a netgroup entry specifies an IP address, and that IP address can be resolved to a name, mountd will currently only test whether the canonical name and any aliases are in the netgroup, and does not test whether the IP address is in the netgroup (IP addresses which do not resolve to a name are already checked against the netgroup).

Quoted 5 lines

This patch adds the check to see whether the IP addresses are in the netgroup.

Committed...

steved.

Quoted 32 lines
support/export/client.c +15 -1
index 95156f0..f6c58f2 100644
@@ -686,6 +686,21 @@ check_netgroup(const nfs_client *clp, const struct addrinfo *ai)
 		}
 	}
 
+	/* check whether the IP itself is in the netgroup */
+	for (tmp = ai ; tmp != NULL ; tmp = tmp->ai_next) {
+		free(hname);
+		hname = calloc(INET6_ADDRSTRLEN, 1);
+
+		if (inet_ntop(tmp->ai_family, &(((struct sockaddr_in *)tmp->ai_addr)->sin_addr), hname, INET6_ADDRSTRLEN) != hname) {
+			xlog(D_GENERAL, "  %s: unable to inet_ntop addrinfo %p: %m", __func__, tmp, errno);
+			goto out;
+		}
+		if (innetgr(netgroup, hname, NULL, NULL)) {
+			match = 1;
+			goto out;
+		}
+	}
+
 	/* Okay, strip off the domain (if we have one) */
 	dot = strchr(hname, '.');
 	if (dot == NULL)
--

To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html