lockd: fix race in nlm_release()
Subsystems (2)
PATCH 1/1 lockd: fix race in nlm_release()
From: J. Bruce Fields <[email protected]>
The sm_count is decremented to zero but left on the nsm_handles list. So in the space between decrementing sm_count and acquiring nsm_mutex, it is possible for another task to find this nsm_handle, increment the use count and then enter nsm_release itself.
Thus there's nothing to prevent the nsm being freed before we acquire nsm_mutex here.
--- fs/lockd/host.c | 10 ++++------ 1 files changed, 4 insertions(+), 6 deletions(-)
Am I missing something here?--b.
fs/lockd/host.c +4 -6
@@ -529,12 +529,10 @@ nsm_release(struct nsm_handle *nsm) {if (!nsm)return ; +mutex_lock (&nsm_mutex);if (atomic_dec_and_test (&nsm->sm_count)) { -mutex_lock (&nsm_mutex); -if (atomic_read (&nsm->sm_count) ==0 ) { -list_del (&nsm->sm_link); -kfree (nsm); - } -mutex_unlock (&nsm_mutex); +list_del (&nsm->sm_link); +kfree (nsm); } +mutex_unlock (&nsm_mutex); }
Signature · 1 line
1.5.4.rc2.60.gb2e62
Quoted 28 lines · J. Bruce Fields
From: J. Bruce Fields <[email protected]>
The
sm_countis decremented to zero but left on thensm_handleslist. So in the space between decrementingsm_countand acquiringnsm_mutex, it is possible for another task to find thisnsm_handle, increment the use count and then enternsm_releaseitself.Thus there's nothing to prevent the nsm being freed before we acquire
nsm_mutexhere.Signed-off-by J. Bruce Fields <[email protected]>--- fs/lockd/host.c | 10 ++++------ 1 files changed, 4 insertions(+), 6 deletions(-)Am I missing something here?--b.
fs/lockd/host.c +1
-1@@ -529,12 +529,10 @@ nsm_release(struct nsm_handle *nsm) {if (!nsm)return ; +mutex_lock (&nsm_mutex);if (atomic_dec_and_test (&nsm->sm_count)) { -mutex_lock (&nsm_mutex);
fs/lockd/host.c nsm_release(struct nsm_handle *nsm) · line 538
Quoted 10 lines
fs/lockd/host.c +3
-5-if (atomic_read (&nsm->sm_count) ==0 ) { -list_del (&nsm->sm_link); -kfree (nsm); - } -mutex_unlock (&nsm_mutex); +list_del (&nsm->sm_link); +kfree (nsm); } +mutex_unlock (&nsm_mutex); }
It would be nice to get rid of that mutex. That should really be either a spinlock or an rcu-protected list...
Trond
A message that is not in the archive (sent off-list or not yet received): 1203535466.15034.5.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org
Quoted 35 lines · Trond Myklebust
Quoted 33 lines · J. Bruce Fields
From: J. Bruce Fields <[email protected]>
The
sm_countis decremented to zero but left on thensm_handleslist. So in the space between decrementingsm_countand acquiringnsm_mutex, it is possible for another task to find thisnsm_handle, increment the use count and then enternsm_releaseitself.Thus there's nothing to prevent the nsm being freed before we acquire
nsm_mutexhere.Signed-off-by J. Bruce Fields <[email protected]>--- fs/lockd/host.c | 10 ++++------ 1 files changed, 4 insertions(+), 6 deletions(-)Am I missing something here?--b.
fs/lockd/host.c +1
-6@@ -529,12 +529,10 @@ nsm_release(struct nsm_handle *nsm) {if (!nsm)return ; +mutex_lock (&nsm_mutex);if (atomic_dec_and_test (&nsm->sm_count)) { -mutex_lock (&nsm_mutex); -if (atomic_read (&nsm->sm_count) ==0 ) { -list_del (&nsm->sm_link); -kfree (nsm); - } -mutex_unlock (&nsm_mutex);
Quoted 8 lines
fs/lockd/host.c nsm_release(struct nsm_handle *nsm) · line 538
Quoted 5 lines
fs/lockd/host.c +3
-0+list_del (&nsm->sm_link); +kfree (nsm); } +mutex_unlock (&nsm_mutex); }It would be nice to get rid of that mutex. That should really be either a spinlock or an rcu-protected list...
OK, I'll look into doing that next.
If you've got any other suggestions while I'm in the general area, I'm all ears.
--b.
Quoted 45 lines · J. Bruce Fields
Quoted 35 lines · Trond Myklebust
Quoted 33 lines · J. Bruce Fields
From: J. Bruce Fields <[email protected]>
The
sm_countis decremented to zero but left on thensm_handleslist. So in the space between decrementingsm_countand acquiringnsm_mutex, it is possible for another task to find thisnsm_handle, increment the use count and then enternsm_releaseitself.Thus there's nothing to prevent the nsm being freed before we acquire
nsm_mutexhere.Signed-off-by J. Bruce Fields <[email protected]>--- fs/lockd/host.c | 10 ++++------ 1 files changed, 4 insertions(+), 6 deletions(-)Am I missing something here?--b.
fs/lockd/host.c +1
-6@@ -529,12 +529,10 @@ nsm_release(struct nsm_handle *nsm) {if (!nsm)return ; +mutex_lock (&nsm_mutex);if (atomic_dec_and_test (&nsm->sm_count)) { -mutex_lock (&nsm_mutex); -if (atomic_read (&nsm->sm_count) ==0 ) { -list_del (&nsm->sm_link); -kfree (nsm); - } -mutex_unlock (&nsm_mutex);Quoted 8 lines
fs/lockd/host.c nsm_release(struct nsm_handle *nsm) · line 538
Quoted 5 lines
fs/lockd/host.c +3
-0+list_del (&nsm->sm_link); +kfree (nsm); } +mutex_unlock (&nsm_mutex); }It would be nice to get rid of that mutex. That should really be either a spinlock or an rcu-protected list...
Quoted 4 lines
OK, I'll look into doing that next.
If you've got any other suggestions while I'm in the general area, I'm all ears.
Just the usual plea to replace the host->h_server flag with 2 separate
lists: one list of client nlm_hosts, and one list of server nlm_hosts :-)
...Oh and a minor optimisation: If we're using a loopback mount, I don't think we'll ever need to monitor 'localhost' :-)
A message that is not in the archive (sent off-list or not yet received): 1203536918.15034.11.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org
Quoted 46 lines · Trond Myklebust
Quoted 45 lines · J. Bruce Fields
Quoted 43 lines · Trond Myklebust
Quoted 28 lines · J. Bruce Fields
From: J. Bruce Fields <[email protected]>
The
sm_countis decremented to zero but left on thensm_handleslist. So in the space between decrementingsm_countand acquiringnsm_mutex, it is possible for another task to find thisnsm_handle, increment the use count and then enternsm_releaseitself.Thus there's nothing to prevent the nsm being freed before we acquire
nsm_mutexhere.Signed-off-by J. Bruce Fields <[email protected]>--- fs/lockd/host.c | 10 ++++------ 1 files changed, 4 insertions(+), 6 deletions(-)Am I missing something here?--b.
fs/lockd/host.c +1
-1@@ -529,12 +529,10 @@ nsm_release(struct nsm_handle *nsm) {if (!nsm)return ; +mutex_lock (&nsm_mutex);if (atomic_dec_and_test (&nsm->sm_count)) { -mutex_lock (&nsm_mutex);fs/lockd/host.c nsm_release(struct nsm_handle *nsm) · line 538
Quoted 10 lines
fs/lockd/host.c +3
-5-if (atomic_read (&nsm->sm_count) ==0 ) { -list_del (&nsm->sm_link); -kfree (nsm); - } -mutex_unlock (&nsm_mutex); +list_del (&nsm->sm_link); +kfree (nsm); } +mutex_unlock (&nsm_mutex); }It would be nice to get rid of that mutex. That should really be either a spinlock or an rcu-protected list...
Quoted 8 lines
Quoted 4 lines
OK, I'll look into doing that next.
If you've got any other suggestions while I'm in the general area, I'm all ears.
Just the usual plea to replace the
host->h_serverflag with 2 separate
lists: one list of clientnlm_hosts, and one list of servernlm_hosts:-)
I have no objection to that, but my NLM IPv6 patches will be significantly affected by such a change right at this point. Can we hold off until the IPv6 work is integrated, or make this change part of the IPv6 work itself?
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
Quoted 9 lines · Chuck Lever
Quoted 3 lines · Trond Myklebust
Just the usual plea to replace the
host->h_serverflag with 2 separate
lists: one list of clientnlm_hosts, and one list of servernlm_hosts:-)I have no objection to that, but my NLM IPv6 patches will be significantly affected by such a change right at this point. Can we hold off until the IPv6 work is integrated, or make this change part of the IPv6 work itself?
Just speak up before I try to merge it, and we'll work something out....
--b.
Quoted 26 lines · Trond Myklebust
Quoted 24 lines · J. Bruce Fields
Quoted 23 lines · Trond Myklebust
Quoted 21 lines · J. Bruce Fields
From: J. Bruce Fields <[email protected]>
The
sm_countis decremented to zero but left on thensm_handleslist. So in the space between decrementingsm_countand acquiringnsm_mutex, it is possible for another task to find thisnsm_handle, increment the use count and then enternsm_releaseitself.Thus there's nothing to prevent the nsm being freed before we acquire
nsm_mutexhere.Signed-off-by J. Bruce Fields <[email protected]>--- fs/lockd/host.c | 10 ++++------ 1 files changed, 4 insertions(+), 6 deletions(-)Am I missing something here?--b.
fs/lockd/host.c +0
-0
...
Quoted 6 lines
Quoted 2 lines
If you've got any other suggestions while I'm in the general area, I'm all ears.
Just the usual plea to replace the
host->h_serverflag with 2 separate
lists: one list of clientnlm_hosts, and one list of servernlm_hosts:-)
OK, I'm looking at that.
Quoted 2 lines
...Oh and a minor optimisation: If we're using a loopback mount, I don't think we'll ever need to monitor 'localhost' :-)
I assumed one of the only uses for loopback mounts was for testing and development, in which case it's better to keep the loopback behavior similar to non-loopback behavior, even if it's a little silly. No?
--b.
Quoted 43 lines · J. Bruce Fields
Quoted 28 lines · Trond Myklebust
Quoted 26 lines · J. Bruce Fields
Quoted 24 lines · Trond Myklebust
Quoted 22 lines · J. Bruce Fields
From: J. Bruce Fields <[email protected]>
The
sm_countis decremented to zero but left on thensm_handleslist. So in the space between decrementingsm_countand acquiringnsm_mutex, it is possible for another task to find thisnsm_handle, increment the use count and then enternsm_releaseitself.Thus there's nothing to prevent the nsm being freed before we acquire
nsm_mutexhere.Signed-off-by J. Bruce Fields <[email protected]>--- fs/lockd/host.c | 10 ++++------ 1 files changed, 4 insertions(+), 6 deletions(-)Am I missing something here?--b.
fs/lockd/host.c +0
-0...
Quoted 7 lines
Quoted 3 lines
If you've got any other suggestions while I'm in the general area, I'm all ears.
Just the usual plea to replace the
host->h_serverflag with 2 separate
lists: one list of clientnlm_hosts, and one list of servernlm_hosts:-)OK, I'm looking at that.
Quoted 7 lines
Quoted 3 lines
...Oh and a minor optimisation: If we're using a loopback mount, I don't think we'll ever need to monitor 'localhost' :-)
I assumed one of the only uses for loopback mounts was for testing and development, in which case it's better to keep the loopback behavior similar to non-loopback behavior, even if it's a little silly. No?
We have encountered a number of customers, who are trying to deploy in a cluster architecture, who mount over loopback. We have tried to convince them that this is a bad idea and/or that they should use something like bind mounts instead, but they insist.
We try not to look too surprised when they encounter issues... :-)
ps