Skip to contentSkip to conversation

NFSv4: use unique client identifiers in network namespaces

PATCH Superseded Benjamin Coddington 3 participants 9 messages Feb 8, 2022 – Feb 28, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFSv4: use unique client identifiers in network namespaces

In order to differentiate client state, assign a random uuid to the uniquifing portion of the client identifier when a network namespace is created. Containers may still override this value if they wish to maintain stable client identifiers by writing to /sys/fs/nfs/net/client/identifier, either by udev rules or other means.

---
 fs/nfs/sysfs.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
fs/nfs/sysfs.c +14 -0
index 8cb70755e3c9..9b811323fd7f 100644
@@ -167,6 +167,18 @@ static struct nfs_netns_client *nfs_netns_client_alloc(struct kobject *parent,
 	return NULL;
 }
 
+static void assign_unique_clientid(struct nfs_netns_client *clp)
+{
+	unsigned char client_uuid[16];
+	char *uuid_str = kmalloc(UUID_STRING_LEN + 1, GFP_KERNEL);
+
+	if (uuid_str) {
+		generate_random_uuid(client_uuid);
+		sprintf(uuid_str, "%pU", client_uuid);
+		rcu_assign_pointer(clp->identifier, uuid_str);
+	}
+}
+
 void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net)
 {
 	struct nfs_netns_client *clp;
@@ -174,6 +186,8 @@ void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net)
 	clp = nfs_netns_client_alloc(nfs_client_kobj, net);
 	if (clp) {
 		netns->nfs_client = clp;
+		if (net != &init_net)
+			assign_unique_clientid(clp);
 		kobject_uevent(&clp->kobject, KOBJ_ADD);
 	}
 }
Signature · 1 line
2.31.1
#1 lore raw
Quoted 39 lines · Benjamin Coddington

In order to differentiate client state, assign a random uuid to the uniquifing portion of the client identifier when a network namespace is
created.  Containers may still override this value if they wish to maintain
stable client identifiers by writing to /sys/fs/nfs/net/client/identifier,
either by udev rules or other means.

---
 fs/nfs/sysfs.c | 14 ++++++++++++++

 1 file changed, 14 insertions(+)
fs/nfs/sysfs.c +0 -0
index 8cb70755e3c9..9b811323fd7f 100644
@@ -167,6 +167,18 @@ static struct nfs_netns_client
 *nfs_netns_client_alloc(struct kobject *parent,
         return NULL;
  }

fs/nfs/sysfs.c +12 -0
+static void assign_unique_clientid(struct nfs_netns_client *clp)
+{
+       unsigned char client_uuid[16];
+       char *uuid_str = kmalloc(UUID_STRING_LEN + 1, GFP_KERNEL);
+
+       if (uuid_str) {
+               generate_random_uuid(client_uuid);
+               sprintf(uuid_str, "%pU", client_uuid);
+               rcu_assign_pointer(clp->identifier, uuid_str);
+       }
+}
+

 void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net) {
        struct nfs_netns_client *clp;

fs/nfs/sysfs.c void nfs_netns_sysfs_setup(struct nfs_net *netns, · line 191

Quoted 6 lines
fs/nfs/sysfs.c +2 -0
@@ -174,6 +186,8 @@ void nfs_netns_sysfs_setup(struct nfs_net *netns,
 struct net *net)
         clp = nfs_netns_client_alloc(nfs_client_kobj, net);
         if (clp) {
                 netns->nfs_client = clp;
+               if (net != &init_net)
+                       assign_unique_clientid(clp);

Why shouldn't this go in nfs_netns_client_alloc? At this point you've already published the pointer in netns, so you're prone to races.

Also, why the exclusion of init_net?

Quoted 3 lines
fs/nfs/sysfs.c +0 -0
                 kobject_uevent(&clp->kobject, KOBJ_ADD);
         }

 }

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
#2 lore raw
Quoted 43 lines · Trond Myklebust
Quoted 42 lines · Benjamin Coddington

In order to differentiate client state, assign a random uuid to the uniquifing portion of the client identifier when a network namespace is
created.  Containers may still override this value if they wish to maintain
stable client identifiers by writing to /sys/fs/nfs/net/client/identifier,
either by udev rules or other means.

---
 fs/nfs/sysfs.c | 14 ++++++++++++++

 1 file changed, 14 insertions(+)
fs/nfs/sysfs.c +0 -0
index 8cb70755e3c9..9b811323fd7f 100644
@@ -167,6 +167,18 @@ static struct nfs_netns_client
 *nfs_netns_client_alloc(struct kobject *parent,
         return NULL;
  }

fs/nfs/sysfs.c +4 -0
+static void assign_unique_clientid(struct nfs_netns_client *clp)
+{
+       unsigned char client_uuid[16];
+       char *uuid_str = kmalloc(UUID_STRING_LEN + 1, 

GFP_KERNEL);
+
+       if (uuid_str) {
+               generate_random_uuid(client_uuid); +               sprintf(uuid_str, "%pU", client_uuid); +               rcu_assign_pointer(clp->identifier, uuid_str);
+       }

fs/nfs/sysfs.c +2 -0
+}
+

 void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net) {
        struct nfs_netns_client *clp;

fs/nfs/sysfs.c +0 -0
@@ -174,6 +186,8 @@ void nfs_netns_sysfs_setup(struct nfs_net *netns,
 struct net *net)
Quoted 8 lines

fs/nfs/sysfs.c void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net) · line 190

Quoted 5 lines
fs/nfs/sysfs.c +2 -0
         clp = nfs_netns_client_alloc(nfs_client_kobj, net);
         if (clp) {
                 netns->nfs_client = clp;
+               if (net != &init_net)
+                       assign_unique_clientid(clp);

Why shouldn't this go in nfs_netns_client_alloc? At this point you've already published the pointer in netns, so you're prone to races.

No reason it shouldn't, I'll put it there if that's what you want.

I thought that's why it was RCU-ed, and figured we'd just do it before the uevent.

Quoted 1 line

Also, why the exclusion of init_net?

Because we're unique enough if we're not in a network namespace, and any additional uniqueness we might need (due to NAT, or cloned VMs) /should/ be getting from udev, as you envisioned. That way, if we are getting uniquified, its from a source that's likely persistent/deterministic. If we just generate a random uniquifier, its going to be different next boot if there's no udev rule and userspace helpers. That's going to make things a lot worse for simple setups.

Ben

#3 lore raw
Quoted 60 lines · Benjamin Coddington
Quoted 49 lines · Trond Myklebust
Quoted 48 lines · Benjamin Coddington

In order to differentiate client state, assign a random uuid to the
uniquifing portion of the client identifier when a network namespace
is
created.  Containers may still override this value if they wish to
maintain
stable client identifiers by writing to /sys/fs/nfs/net/client/identifier,
either by udev rules or other means.

---
 fs/nfs/sysfs.c | 14 ++++++++++++++

 1 file changed, 14 insertions(+)
fs/nfs/sysfs.c +0 -0
index 8cb70755e3c9..9b811323fd7f 100644
@@ -167,6 +167,18 @@ static struct nfs_netns_client
 *nfs_netns_client_alloc(struct kobject *parent,
         return NULL;
  }

fs/nfs/sysfs.c +4 -0
+static void assign_unique_clientid(struct nfs_netns_client *clp)
+{
+       unsigned char client_uuid[16];
+       char *uuid_str = kmalloc(UUID_STRING_LEN + 1, 

GFP_KERNEL);
+
+       if (uuid_str) {
+               generate_random_uuid(client_uuid); +               sprintf(uuid_str, "%pU", client_uuid); +               rcu_assign_pointer(clp->identifier, uuid_str);
+       }

fs/nfs/sysfs.c +2 -0
+}
+

 void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net)
 {
        struct nfs_netns_client *clp;

fs/nfs/sysfs.c +0 -0
@@ -174,6 +186,8 @@ void nfs_netns_sysfs_setup(struct nfs_net
 *netns,
 struct net *net)
         clp = nfs_netns_client_alloc(nfs_client_kobj, net);
Quoted 8 lines

fs/nfs/sysfs.c void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net) · line 190

Quoted 4 lines
fs/nfs/sysfs.c +2 -0
         if (clp) {
                 netns->nfs_client = clp;
+               if (net != &init_net)
+                       assign_unique_clientid(clp);

Why shouldn't this go in nfs_netns_client_alloc? At this point you've
already published the pointer in netns, so you're prone to races.

Quoted 6 lines

No reason it shouldn't, I'll put it there if that's what you want.

I thought that's why it was RCU-ed, and figured we'd just do it before
the
uevent.

If the value is being set from userspace, then it is up to userland to solve any problems. However if we're also setting a value from the kernel, then we have to make sure that we don't clobber any changes made from userspace. AFAICS, the best way to do that is to initialise before we publish.

Quoted 20 lines
Quoted 2 lines

Also, why the exclusion of init_net?

Because we're unique enough if we're not in a network namespace, and any
additional uniqueness we might need (due to NAT, or cloned VMs) /should/
be
getting from udev, as you envisioned.  That way, if we are getting uniquified, its from a source that's likely persistent/deterministic.
If we
just generate a random uniquifier, its going to be different next boot
if
there's no udev rule and userspace helpers.  That's going to make things
a
lot worse for simple setups.

So you're following up with changes to nfs-utils to configure udev?

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
#4 lore raw
Quoted 13 lines · Trond Myklebust
Quoted 11 lines · Benjamin Coddington
Quoted 1 line · Trond Myklebust

Also, why the exclusion of init_net?

Because we're unique enough if we're not in a network namespace, and any additional uniqueness we might need (due to NAT, or cloned VMs) /should/ be getting from udev, as you envisioned.  That way, if we are getting uniquified, its from a source that's likely persistent/deterministic.  If we just generate a random uniquifier, its going to be different next boot if there's no udev rule and userspace helpers.  That's going to make things a lot worse for simple setups.

Quoted 1 line

So you're following up with changes to nfs-utils to configure udev?

Yes.

Ben

#5 lore raw
In reply to Benjamin Coddington
Quoted 62 lines · Benjamin Coddington
Quoted 43 lines · Trond Myklebust
Quoted 42 lines · Benjamin Coddington

In order to differentiate client state, assign a random uuid to the uniquifing portion of the client identifier when a network namespace is
created.  Containers may still override this value if they wish to maintain
stable client identifiers by writing to /sys/fs/nfs/net/client/identifier,
either by udev rules or other means.

---
 fs/nfs/sysfs.c | 14 ++++++++++++++

 1 file changed, 14 insertions(+)
fs/nfs/sysfs.c +0 -0
index 8cb70755e3c9..9b811323fd7f 100644
@@ -167,6 +167,18 @@ static struct nfs_netns_client
 *nfs_netns_client_alloc(struct kobject *parent,
         return NULL;
  }

fs/nfs/sysfs.c +4 -0
+static void assign_unique_clientid(struct nfs_netns_client *clp)
+{
+       unsigned char client_uuid[16];
+       char *uuid_str = kmalloc(UUID_STRING_LEN + 1, 

GFP_KERNEL);
+
+       if (uuid_str) {
+               generate_random_uuid(client_uuid); +               sprintf(uuid_str, "%pU", client_uuid); +               rcu_assign_pointer(clp->identifier, uuid_str);
+       }

fs/nfs/sysfs.c +2 -0
+}
+

 void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net) {
        struct nfs_netns_client *clp;

fs/nfs/sysfs.c +0 -0
@@ -174,6 +186,8 @@ void nfs_netns_sysfs_setup(struct nfs_net *netns,
 struct net *net)
Quoted 8 lines

fs/nfs/sysfs.c void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net) · line 190

Quoted 5 lines
fs/nfs/sysfs.c +2 -0
         clp = nfs_netns_client_alloc(nfs_client_kobj, net);
         if (clp) {
                 netns->nfs_client = clp;
+               if (net != &init_net)
+                       assign_unique_clientid(clp);

Why shouldn't this go in nfs_netns_client_alloc? At this point you've already published the pointer in netns, so you're prone to races.

No reason it shouldn't, I'll put it there if that's what you want.

I thought that's why it was RCU-ed, and figured we'd just do it before the
uevent.

Quoted 1 line

Also, why the exclusion of init_net?

Quoted 11 lines

Because we're unique enough if we're not in a network namespace, and any additional uniqueness we might need (due to NAT, or cloned VMs) /should/ be
getting from udev, as you envisioned. That way, if we are getting uniquified, its from a source that's likely persistent/deterministic. If we
just generate a random uniquifier, its going to be different next boot if
there's no udev rule and userspace helpers. That's going to make things a
lot worse for simple setups.

I liked this patch at first, but I no longer think it is a good idea.

It is quite possible today for containers to provide sufficient uniqueness simply by setting a unique hostname before the first NFS mount.
Quite possibly some containers already do this, and are working perfectly.

If we add new randomness, the they will get a different identifier on each boot. This is bad for exactly the same reason that it is bad for "net == &init_net".

i.e. I believe this patch could cause a regression for working sites. The regression may not be immediately obvious, but it may still be there.
For this reason, I think this patch should be dropped.

Thanks,
NeilBrown

#6 lore raw
Quoted 85 lines · NeilBrown
Quoted 64 lines · Benjamin Coddington
Quoted 45 lines · Trond Myklebust
Quoted 44 lines · Benjamin Coddington

In order to differentiate client state, assign a random uuid to the uniquifing portion of the client identifier when a network namespace is
created.  Containers may still override this value if they wish to maintain
stable client identifiers by writing to /sys/fs/nfs/net/client/identifier,
either by udev rules or other means.

---
 fs/nfs/sysfs.c | 14 ++++++++++++++

 1 file changed, 14 insertions(+)
fs/nfs/sysfs.c +0 -0
index 8cb70755e3c9..9b811323fd7f 100644
@@ -167,6 +167,18 @@ static struct nfs_netns_client
 *nfs_netns_client_alloc(struct kobject *parent,
         return NULL;
  }

fs/nfs/sysfs.c +4 -0
+static void assign_unique_clientid(struct nfs_netns_client *clp)
+{
+       unsigned char client_uuid[16];
+       char *uuid_str = kmalloc(UUID_STRING_LEN + 1,

GFP_KERNEL);
+
+       if (uuid_str) {
+               generate_random_uuid(client_uuid); +               sprintf(uuid_str, "%pU", client_uuid);
+               rcu_assign_pointer(clp->identifier, uuid_str);
+       }

fs/nfs/sysfs.c +2 -0
+}
+

 void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net) {
        struct nfs_netns_client *clp;

fs/nfs/sysfs.c +0 -0
@@ -174,6 +186,8 @@ void nfs_netns_sysfs_setup(struct nfs_net 
 *netns,
 struct net *net)
Quoted 8 lines

fs/nfs/sysfs.c void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net) · line 190

Quoted 5 lines
fs/nfs/sysfs.c +2 -0
         clp = nfs_netns_client_alloc(nfs_client_kobj, net);
         if (clp) {
                 netns->nfs_client = clp;
+               if (net != &init_net)
+                       assign_unique_clientid(clp);

Why shouldn't this go in nfs_netns_client_alloc? At this point you've already published the pointer in netns, so you're prone to races.

No reason it shouldn't, I'll put it there if that's what you want.

I thought that's why it was RCU-ed, and figured we'd just do it before the
uevent.

Quoted 1 line

Also, why the exclusion of init_net?

Quoted 11 lines

Because we're unique enough if we're not in a network namespace, and any additional uniqueness we might need (due to NAT, or cloned VMs) /should/ be
getting from udev, as you envisioned. That way, if we are getting uniquified, its from a source that's likely persistent/deterministic. If we
just generate a random uniquifier, its going to be different next boot if
there's no udev rule and userspace helpers. That's going to make things a
lot worse for simple setups.

I liked this patch at first, but I no longer think it is a good idea.

It is quite possible today for containers to provide sufficient uniqueness simply by setting a unique hostname before the first NFS mount.
Quite possibly some containers already do this, and are working perfectly.

Quoted 8 lines

If we add new randomness, the they will get a different identifier on each boot. This is bad for exactly the same reason that it is bad for "net == &init_net".

i.e. I believe this patch could cause a regression for working sites. The regression may not be immediately obvious, but it may still be there.
For this reason, I think this patch should be dropped.

I agree, Trond please drop this patch.

Ben

#7 lore raw
Quoted 110 lines · Benjamin Coddington
Quoted 108 lines · NeilBrown
Quoted 83 lines · Benjamin Coddington
Quoted 52 lines · Trond Myklebust
Quoted 51 lines · Benjamin Coddington

In order to differentiate client state, assign a random uuid to the
uniquifing portion of the client identifier when a network namespace
is
created.  Containers may still override this value if they wish to
maintain
stable client identifiers by writing to /sys/fs/nfs/net/client/identifier,
either by udev rules or other means.

---
 fs/nfs/sysfs.c | 14 ++++++++++++++

 1 file changed, 14 insertions(+)
fs/nfs/sysfs.c +0 -0
index 8cb70755e3c9..9b811323fd7f 100644
@@ -167,6 +167,18 @@ static struct nfs_netns_client
 *nfs_netns_client_alloc(struct kobject *parent,
         return NULL;
  }


+static void assign_unique_clientid(struct nfs_netns_client *clp)
+{
+       unsigned char client_uuid[16];
+       char *uuid_str = kmalloc(UUID_STRING_LEN + 1, GFP_KERNEL);
+
+       if (uuid_str) {
+               generate_random_uuid(client_uuid); +               sprintf(uuid_str, "%pU", client_uuid);
+               rcu_assign_pointer(clp->identifier, uuid_str);
+       }

fs/nfs/sysfs.c +2 -0
+}
+

 void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net)
 {
        struct nfs_netns_client *clp;

fs/nfs/sysfs.c +0 -0
@@ -174,6 +186,8 @@ void nfs_netns_sysfs_setup(struct nfs_net
 *netns,
 struct net *net)
         clp = nfs_netns_client_alloc(nfs_client_kobj, net);
         if (clp) {
Quoted 8 lines

fs/nfs/sysfs.c void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net) · line 190

Quoted 3 lines
fs/nfs/sysfs.c +2 -0
                 netns->nfs_client = clp;
+               if (net != &init_net)
+                       assign_unique_clientid(clp);

Why shouldn't this go in nfs_netns_client_alloc? At this point you've
already published the pointer in netns, so you're prone to races.

No reason it shouldn't, I'll put it there if that's what you want.

I thought that's why it was RCU-ed, and figured we'd just do it before
the
uevent.

Quoted 1 line

Also, why the exclusion of init_net?

Because we're unique enough if we're not in a network namespace, and
any
additional uniqueness we might need (due to NAT, or cloned VMs) /should/
be
getting from udev, as you envisioned.  That way, if we are getting
uniquified, its from a source that's likely persistent/deterministic.

Quoted 8 lines

If we
just generate a random uniquifier, its going to be different next boot
if
there's no udev rule and userspace helpers.  That's going to make things
a
lot worse for simple setups.

I liked this patch at first, but I no longer think it is a good idea.

It is quite possible today for containers to provide sufficient uniqueness simply by setting a unique hostname before the first NFS mount.
Quite possibly some containers already do this, and are working perfectly.

If we add new randomness, the they will get a different identifier on
each boot.  This is bad for exactly the same reason that it is bad for
"net == &init_net".

Quoted 9 lines
Quoted 5 lines

i.e.  I believe this patch could cause a regression for working sites.
The regression may not be immediately obvious, but it may still be there.
For this reason, I think this patch should be dropped.

I agree, Trond please drop this patch.

Since it was already pushed to linux-next, it will have to be reverted.

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
#8 lore raw
Quoted 23 lines · Trond Myklebust
Quoted 22 lines · Benjamin Coddington
Quoted 20 lines · NeilBrown

I liked this patch at first, but I no longer think it is a good idea.

It is quite possible today for containers to provide sufficient uniqueness simply by setting a unique hostname before the first NFS mount.
Quite possibly some containers already do this, and are working perfectly.

If we add new randomness, the they will get a different identifier on
each boot.  This is bad for exactly the same reason that it is bad for
"net == &init_net".

i.e.  I believe this patch could cause a regression for working sites.
The regression may not be immediately obvious, but it may still be there.
For this reason, I think this patch should be dropped.

Quoted 5 lines
Quoted 3 lines

I agree, Trond please drop this patch.

Since it was already pushed to linux-next, it will have to be reverted.

I'm not seeing it on any branch on linux-next. I presume no one's pulled your linux-next branch. Are you not able to drop it from your linux-next branch?

Ben