File 0181-mountd-reject-unknown-client-IP-when-use_ipaddr.patch of Package nfs-utils.33226

From 855a676334c8e8d3cf87e5053debcae79cc817f1 Mon Sep 17 00:00:00 2001
From: NeilBrown <neil@brown.name>
Date: Fri, 19 Feb 2021 11:31:01 +1100
Subject: [PATCH] mountd: reject unknown client IP when !use_ipaddr.

When use_ipaddr is not in effect, an auth_unix_ip lookup request from
the kernel for an unknown client will be rejected.
When it IS in effect, these requests are always granted with the IP
address being mapped to a string form of the address, preceded by a '$'.

This is inconsistent behaviour and could present a small information
leak.
It means that, for example, a SETCLIENT NFSv4 request may or may not
succeed depending on an internal setting in rpc.mountd.

This is easily rectified by always checking if the client is known.

Signed-off-by: NeilBrown <neil@brown.name>
---
 utils/mountd/cache.c |   17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

--- a/utils/mountd/cache.c
+++ b/utils/mountd/cache.c
@@ -82,6 +82,7 @@ static void auth_unix_ip(FILE *f)
 	char class[20];
 	char ipaddr[INET6_ADDRSTRLEN + 1];
 	char *client = NULL;
+	struct addrinfo *ai = NULL;
 	struct addrinfo *tmp = NULL;
 	if (readline(fileno(f), &lbuf, &lbuflen) != 1)
 		return;
@@ -103,20 +104,16 @@ static void auth_unix_ip(FILE *f)
 
 	auth_reload();
 
-	/* addr is a valid, interesting address, find the domain name... */
-	if (!use_ipaddr) {
-		struct addrinfo *ai = NULL;
-
-		ai = client_resolve(tmp->ai_addr);
-		if (ai) {
-			client = client_compose(ai);
-			freeaddrinfo(ai);
-		}
+	/* addr is a valid address, find the domain name... */
+	ai = client_resolve(tmp->ai_addr);
+	if (ai) {
+		client = client_compose(ai);
+		freeaddrinfo(ai);
 	}
 	qword_print(f, "nfsd");
 	qword_print(f, ipaddr);
 	qword_printtimefrom(f, DEFAULT_TTL);
-	if (use_ipaddr) {
+	if (use_ipaddr && client) {
 		memmove(ipaddr + 1, ipaddr, strlen(ipaddr) + 1);
 		ipaddr[0] = '$';
 		qword_print(f, ipaddr);
openSUSE Build Service is sponsored by