All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] nfs-utils: Add check of clientaddr argument
@ 2018-05-24 20:05 Olga Kornievskaia
  2018-05-25  0:50 ` Chuck Lever
  0 siblings, 1 reply; 16+ messages in thread
From: Olga Kornievskaia @ 2018-05-24 20:05 UTC (permalink / raw)
  To: steved; +Cc: linux-nfs

If the user supplies a clientaddr value, it should be either
a special value of either IPV4/IPV6 any address or a local address
on the same network that the server being mounted. Otherwise, we
disallow the client to use an arbitrary value of the clientaddr value.
This value is used to construct a client id of SETCLIENTID and
providing a false value can interfere with the real owner's mount.

Signed-off-by: Olga Kornievskaia <kolga@netapp.com>
---
 utils/mount/stropts.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c
index d1b0708..44a6ff5 100644
--- a/utils/mount/stropts.c
+++ b/utils/mount/stropts.c
@@ -229,7 +229,8 @@ static int nfs_append_addr_option(const struct sockaddr *sap,
 
 /*
  * Called to discover our address and append an appropriate 'clientaddr='
- * option to the options string.
+ * option to the options string. If the supplied 'clientaddr=' value does
+ * not match either IPV4/IPv6 any or a local address, then fail the mount.
  *
  * Returns 1 if 'clientaddr=' option created successfully or if
  * 'clientaddr=' option is already present; otherwise zero.
@@ -242,11 +243,26 @@ static int nfs_append_clientaddr_option(const struct sockaddr *sap,
 	struct sockaddr *my_addr = &address.sa;
 	socklen_t my_len = sizeof(address);
 
-	if (po_contains(options, "clientaddr") == PO_FOUND)
-		return 1;
-
 	nfs_callback_address(sap, salen, my_addr, &my_len);
 
+	if (po_contains(options, "clientaddr") == PO_FOUND) {
+		char *addr = po_get(options, "clientaddr");
+		char address[NI_MAXHOST];
+
+		if (!strcmp(addr, "0.0.0.0") || !strcmp(addr, "::"))
+			return 1;
+		if (!nfs_present_sockaddr(my_addr, my_len, address,
+						sizeof(address)))
+			goto out;
+
+		if (strcmp(addr, address)) {
+			nfs_error(_("%s: failed to validate clientaddr "
+					"address"), progname);
+			return 0;
+		}
+		return 1;
+	}
+out:
 	return nfs_append_generic_address_option(my_addr, my_len,
 							"clientaddr", options);
 }
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread
* [PATCH 1/1] nfs-utils: Add check of clientaddr argument
@ 2018-05-24 20:03 Olga Kornievskaia
  0 siblings, 0 replies; 16+ messages in thread
From: Olga Kornievskaia @ 2018-05-24 20:03 UTC (permalink / raw)
  To: steved; +Cc: linux-nfs

If the user supplies a clientaddr value, it should be either
a special value of either IPV4/IPV6 any address or a local address
on the same network that the server being mounted. Otherwise, we
disallow the client to use an arbitrary value of the clientaddr value.
This value is used to construct a client id of SETCLIENTID and
providing a false value can interfere with the real owner's mount.

Signed-off-by: Olga Kornievskaia <kolga@netapp.com>
---
 utils/mount/stropts.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c
index d1b0708..44a6ff5 100644
--- a/utils/mount/stropts.c
+++ b/utils/mount/stropts.c
@@ -229,7 +229,8 @@ static int nfs_append_addr_option(const struct sockaddr *sap,
 
 /*
  * Called to discover our address and append an appropriate 'clientaddr='
- * option to the options string.
+ * option to the options string. If the supplied 'clientaddr=' value does
+ * not match either IPV4/IPv6 any or a local address, then fail the mount.
  *
  * Returns 1 if 'clientaddr=' option created successfully or if
  * 'clientaddr=' option is already present; otherwise zero.
@@ -242,11 +243,26 @@ static int nfs_append_clientaddr_option(const struct sockaddr *sap,
 	struct sockaddr *my_addr = &address.sa;
 	socklen_t my_len = sizeof(address);
 
-	if (po_contains(options, "clientaddr") == PO_FOUND)
-		return 1;
-
 	nfs_callback_address(sap, salen, my_addr, &my_len);
 
+	if (po_contains(options, "clientaddr") == PO_FOUND) {
+		char *addr = po_get(options, "clientaddr");
+		char address[NI_MAXHOST];
+
+		if (!strcmp(addr, "0.0.0.0") || !strcmp(addr, "::"))
+			return 1;
+		if (!nfs_present_sockaddr(my_addr, my_len, address,
+						sizeof(address)))
+			goto out;
+
+		if (strcmp(addr, address)) {
+			nfs_error(_("%s: failed to validate clientaddr "
+					"address"), progname);
+			return 0;
+		}
+		return 1;
+	}
+out:
 	return nfs_append_generic_address_option(my_addr, my_len,
 							"clientaddr", options);
 }
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2018-06-02 16:34 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-24 20:05 [PATCH 1/1] nfs-utils: Add check of clientaddr argument Olga Kornievskaia
2018-05-25  0:50 ` Chuck Lever
2018-05-25 14:02   ` Olga Kornievskaia
2018-05-25 16:24     ` Chuck Lever
2018-05-25 16:44       ` Olga Kornievskaia
2018-05-25 16:47         ` Olga Kornievskaia
2018-05-25 17:05           ` Chuck Lever
2018-05-25 17:14             ` Olga Kornievskaia
2018-05-25 17:04         ` Chuck Lever
2018-05-25 22:35           ` Chuck Lever
2018-05-29 20:07             ` Olga Kornievskaia
2018-05-29 20:53               ` Chuck Lever
2018-06-01 21:42                 ` Chuck Lever
2018-06-02 13:37                   ` Olga Kornievskaia
2018-06-02 16:34                     ` Chuck Lever
  -- strict thread matches above, loose matches on Subject: below --
2018-05-24 20:03 Olga Kornievskaia

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.