Skip to contentSkip to conversation

NFSv4: nfs4_state_manager() vs. nfs_server_remove_lists()

PATCH Superseded Steve Dickson 3 participants 5 messages Sep 17, 2014 – Sep 18, 2014

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFSv4: nfs4_state_manager() vs. nfs_server_remove_lists()

There is a race between nfs4_state_manager() and nfs_server_remove_lists() that happens during a nfsv3 mount.

The v3 mount notices there is already a supper block so nfs_server_remove_lists() called which uses the nfs_client_lock spin lock to synchronize access to the client list.

At the same time nfs4_state_manager() is running through the client list looking for work to do, using the same lock. When nfs4_state_manager() wins the race to the list, a v3 client pointer is found and not ignored properly which causes the panic.

Moving some protocol checks before the state checking avoids the panic.

---
 fs/nfs/nfs4client.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
fs/nfs/nfs4client.c +10 -9
index 53e435a..7ff4c02 100644
@@ -622,6 +622,16 @@ int nfs41_walk_client_list(struct nfs_client *new,
 
 	spin_lock(&nn->nfs_client_lock);
 	list_for_each_entry(pos, &nn->nfs_client_list, cl_share_link) {
+
+		if (pos->rpc_ops != new->rpc_ops)
+			continue;
+
+		if (pos->cl_proto != new->cl_proto)
+			continue;
+
+		if (pos->cl_minorversion != new->cl_minorversion)
+			continue;
+
 		/* If "pos" isn't marked ready, we can't trust the
 		 * remaining fields in "pos", especially the client
 		 * ID and serverowner fields.  Wait for CREATE_SESSION
@@ -647,15 +657,6 @@ int nfs41_walk_client_list(struct nfs_client *new,
 		if (pos->cl_cons_state != NFS_CS_READY)
 			continue;
 
-		if (pos->rpc_ops != new->rpc_ops)
-			continue;
-
-		if (pos->cl_proto != new->cl_proto)
-			continue;
-
-		if (pos->cl_minorversion != new->cl_minorversion)
-			continue;
-
 		if (!nfs4_match_clientids(pos, new))
 			continue;
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 60 lines · Steve Dickson

There is a race between nfs4_state_manager() and nfs_server_remove_lists() that happens during a nfsv3 mount.

The v3 mount notices there is already a supper block so nfs_server_remove_lists() called which uses the nfs_client_lock spin lock to synchronize access to the client list.

At the same time nfs4_state_manager() is running through the client list looking for work to do, using the same lock. When nfs4_state_manager() wins the race to the list, a v3 client pointer is found and not ignored properly which causes the panic.

Moving some protocol checks before the state checking avoids the panic.

---
 fs/nfs/nfs4client.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
fs/nfs/nfs4client.c +10 -10
index 53e435a..7ff4c02 100644
@@ -622,6 +622,16 @@ int nfs41_walk_client_list(struct nfs_client *new,
 
        spin_lock(&nn->nfs_client_lock);
        list_for_each_entry(pos, &nn->nfs_client_list, cl_share_link) {
+
+               if (pos->rpc_ops != new->rpc_ops)
+                       continue;
+
+               if (pos->cl_proto != new->cl_proto)
+                       continue;
+
+               if (pos->cl_minorversion != new->cl_minorversion)
+                       continue;
+
                /* If "pos" isn't marked ready, we can't trust the
                 * remaining fields in "pos", especially the client
                 * ID and serverowner fields.  Wait for CREATE_SESSION
@@ -647,15 +657,6 @@ int nfs41_walk_client_list(struct nfs_client *new,
                if (pos->cl_cons_state != NFS_CS_READY)
                        continue;
 
-               if (pos->rpc_ops != new->rpc_ops)
-                       continue;
-
-               if (pos->cl_proto != new->cl_proto)
-                       continue;
-
-               if (pos->cl_minorversion != new->cl_minorversion)
-                       continue;
-
                if (!nfs4_match_clientids(pos, new))
                        continue;
 
--
Quoted 2 lines

1.8.3.1

Don't we need the same fix in nfs40_walk_client_list?

Cheers
Trond

Signature · 5 lines
Trond Myklebust

Linux NFS client maintainer, PrimaryData

[email protected]
#2 lore raw
Quoted 60 lines · Trond Myklebust
Quoted 59 lines · Steve Dickson

There is a race between nfs4_state_manager() and nfs_server_remove_lists() that happens during a nfsv3 mount.

The v3 mount notices there is already a supper block so nfs_server_remove_lists() called which uses the nfs_client_lock spin lock to synchronize access to the client list.

At the same time nfs4_state_manager() is running through the client list looking for work to do, using the same lock. When nfs4_state_manager() wins the race to the list, a v3 client pointer is found and not ignored properly which causes the panic.

Moving some protocol checks before the state checking avoids the panic.

---
 fs/nfs/nfs4client.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
fs/nfs/nfs4client.c +10 -9
index 53e435a..7ff4c02 100644
@@ -622,6 +622,16 @@ int nfs41_walk_client_list(struct nfs_client *new,
 
        spin_lock(&nn->nfs_client_lock);
        list_for_each_entry(pos, &nn->nfs_client_list, cl_share_link) {
+
+               if (pos->rpc_ops != new->rpc_ops)
+                       continue;
+
+               if (pos->cl_proto != new->cl_proto)
+                       continue;
+
+               if (pos->cl_minorversion != new->cl_minorversion)
+                       continue;
+
                /* If "pos" isn't marked ready, we can't trust the
                 * remaining fields in "pos", especially the client
                 * ID and serverowner fields.  Wait for CREATE_SESSION
@@ -647,15 +657,6 @@ int nfs41_walk_client_list(struct nfs_client *new,
                if (pos->cl_cons_state != NFS_CS_READY)
                        continue;
 
-               if (pos->rpc_ops != new->rpc_ops)
-                       continue;
-
-               if (pos->cl_proto != new->cl_proto)
-                       continue;
-
-               if (pos->cl_minorversion != new->cl_minorversion)
-                       continue;
-
                if (!nfs4_match_clientids(pos, new))
                        continue;
 
Quoted 4 lines
Quoted 3 lines

--
1.8.3.1

Don't we need the same fix in nfs40_walk_client_list?

Bonus points for finding a way to merge these functions, since they do similar comparisons in the beginning :)

Anna

Quoted 4 lines

Cheers
Trond

#3 lore raw
Quoted 61 lines · Anna Schumaker
Quoted 60 lines · Trond Myklebust
Quoted 59 lines · Steve Dickson

There is a race between nfs4_state_manager() and nfs_server_remove_lists() that happens during a nfsv3 mount.

The v3 mount notices there is already a supper block so nfs_server_remove_lists() called which uses the nfs_client_lock spin lock to synchronize access to the client list.

At the same time nfs4_state_manager() is running through the client list looking for work to do, using the same lock. When nfs4_state_manager() wins the race to the list, a v3 client pointer is found and not ignored properly which causes the panic.

Moving some protocol checks before the state checking avoids the panic.

---
 fs/nfs/nfs4client.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
fs/nfs/nfs4client.c +10 -9
index 53e435a..7ff4c02 100644
@@ -622,6 +622,16 @@ int nfs41_walk_client_list(struct nfs_client *new,
 
        spin_lock(&nn->nfs_client_lock);
        list_for_each_entry(pos, &nn->nfs_client_list, cl_share_link) {
+
+               if (pos->rpc_ops != new->rpc_ops)
+                       continue;
+
+               if (pos->cl_proto != new->cl_proto)
+                       continue;
+
+               if (pos->cl_minorversion != new->cl_minorversion)
+                       continue;
+
                /* If "pos" isn't marked ready, we can't trust the
                 * remaining fields in "pos", especially the client
                 * ID and serverowner fields.  Wait for CREATE_SESSION
@@ -647,15 +657,6 @@ int nfs41_walk_client_list(struct nfs_client *new,
                if (pos->cl_cons_state != NFS_CS_READY)
                        continue;
 
-               if (pos->rpc_ops != new->rpc_ops)
-                       continue;
-
-               if (pos->cl_proto != new->cl_proto)
-                       continue;
-
-               if (pos->cl_minorversion != new->cl_minorversion)
-                       continue;
-
                if (!nfs4_match_clientids(pos, new))
                        continue;
 
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines

--
1.8.3.1

Don't we need the same fix in nfs40_walk_client_list?

Bonus points for finding a way to merge these functions, since they do similar comparisons in the beginning :)

I did talk a look at merging these functions... The start of the functions are similar but the do differ after the state check enough to keep them separate... IMHO...

steved.

#4 lore raw
In reply to Trond Myklebust
Quoted 60 lines · Trond Myklebust
Quoted 59 lines · Steve Dickson

There is a race between nfs4_state_manager() and nfs_server_remove_lists() that happens during a nfsv3 mount.

The v3 mount notices there is already a supper block so nfs_server_remove_lists() called which uses the nfs_client_lock spin lock to synchronize access to the client list.

At the same time nfs4_state_manager() is running through the client list looking for work to do, using the same lock. When nfs4_state_manager() wins the race to the list, a v3 client pointer is found and not ignored properly which causes the panic.

Moving some protocol checks before the state checking avoids the panic.

---
 fs/nfs/nfs4client.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
fs/nfs/nfs4client.c +10 -9
index 53e435a..7ff4c02 100644
@@ -622,6 +622,16 @@ int nfs41_walk_client_list(struct nfs_client *new,
 
        spin_lock(&nn->nfs_client_lock);
        list_for_each_entry(pos, &nn->nfs_client_list, cl_share_link) {
+
+               if (pos->rpc_ops != new->rpc_ops)
+                       continue;
+
+               if (pos->cl_proto != new->cl_proto)
+                       continue;
+
+               if (pos->cl_minorversion != new->cl_minorversion)
+                       continue;
+
                /* If "pos" isn't marked ready, we can't trust the
                 * remaining fields in "pos", especially the client
                 * ID and serverowner fields.  Wait for CREATE_SESSION
@@ -647,15 +657,6 @@ int nfs41_walk_client_list(struct nfs_client *new,
                if (pos->cl_cons_state != NFS_CS_READY)
                        continue;
 
-               if (pos->rpc_ops != new->rpc_ops)
-                       continue;
-
-               if (pos->cl_proto != new->cl_proto)
-                       continue;
-
-               if (pos->cl_minorversion != new->cl_minorversion)
-                       continue;
-
                if (!nfs4_match_clientids(pos, new))
                        continue;
 
Quoted 5 lines
Quoted 3 lines

--
1.8.3.1

Don't we need the same fix in nfs40_walk_client_list?

Yes... Just posted version 2...

steved.

Quoted 4 lines

Cheers
Trond