* [PATCH] eCryptFS: mutex lock-unlock ordering fix
@ 2008-05-20 16:39 Cyrill Gorcunov
2008-05-20 16:42 ` Cyrill Gorcunov
0 siblings, 1 reply; 2+ messages in thread
From: Cyrill Gorcunov @ 2008-05-20 16:39 UTC (permalink / raw)
To: Michael A. Halcrow; +Cc: Andrew Morton, Ingo Molnar, LKML
We should lock/unlock mutexes by a proper way which means
there should not be chains like ABAB but ABBA otherwise the
race window is opened.
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
CC: Michael A. Halcrow <mhalcrow@us.ibm.com>
---
Michael, could you test it please? To be honest I see that
my patch makes source looks ugly unfirtunelly... thoughts?
Any comments are welcome. Maybe I missed something - but I think
the chain LOCK: hash_mux -> mux, UNLOCK: hash_mux -> mux is a bit
weird ;) so please check if I'm wrong.
Index: linux-2.6.git/fs/ecryptfs/miscdev.c
===================================================================
--- linux-2.6.git.orig/fs/ecryptfs/miscdev.c 2008-05-18 18:53:56.000000000 +0400
+++ linux-2.6.git/fs/ecryptfs/miscdev.c 2008-05-20 20:27:33.000000000 +0400
@@ -50,7 +50,6 @@ ecryptfs_miscdev_poll(struct file *file,
current->nsproxy->user_ns);
BUG_ON(rc || !daemon);
mutex_lock(&daemon->mux);
- mutex_unlock(&ecryptfs_daemon_hash_mux);
if (daemon->flags & ECRYPTFS_DAEMON_ZOMBIE) {
printk(KERN_WARNING "%s: Attempt to poll on zombified "
"daemon\n", __func__);
@@ -62,6 +61,7 @@ ecryptfs_miscdev_poll(struct file *file,
goto out_unlock_daemon;
daemon->flags |= ECRYPTFS_DAEMON_IN_POLL;
mutex_unlock(&daemon->mux);
+ mutex_unlock(&ecryptfs_daemon_hash_mux);
poll_wait(file, &daemon->wait, pt);
mutex_lock(&daemon->mux);
if (!list_empty(&daemon->msg_ctx_out_queue))
@@ -69,6 +69,8 @@ ecryptfs_miscdev_poll(struct file *file,
out_unlock_daemon:
daemon->flags &= ~ECRYPTFS_DAEMON_IN_POLL;
mutex_unlock(&daemon->mux);
+ if (mutex_is_locked(&ecryptfs_daemon_hash_mux))
+ mutex_unlock(&ecryptfs_daemon_hash_mux);
return mask;
}
@@ -257,24 +259,23 @@ ecryptfs_miscdev_read(struct file *file,
mutex_lock(&daemon->mux);
if (daemon->flags & ECRYPTFS_DAEMON_ZOMBIE) {
rc = 0;
- mutex_unlock(&ecryptfs_daemon_hash_mux);
printk(KERN_WARNING "%s: Attempt to read from zombified "
"daemon\n", __func__);
goto out_unlock_daemon;
}
if (daemon->flags & ECRYPTFS_DAEMON_IN_READ) {
rc = 0;
- mutex_unlock(&ecryptfs_daemon_hash_mux);
goto out_unlock_daemon;
}
/* This daemon will not go away so long as this flag is set */
daemon->flags |= ECRYPTFS_DAEMON_IN_READ;
- mutex_unlock(&ecryptfs_daemon_hash_mux);
check_list:
if (list_empty(&daemon->msg_ctx_out_queue)) {
+ if (mutex_is_locked(&ecryptfs_daemon_hash_mux))
+ mutex_unlock(&ecryptfs_daemon_hash_mux);
mutex_unlock(&daemon->mux);
- rc = wait_event_interruptible(
- daemon->wait, !list_empty(&daemon->msg_ctx_out_queue));
+ rc = wait_event_interruptible(daemon->wait,
+ !list_empty(&daemon->msg_ctx_out_queue));
mutex_lock(&daemon->mux);
if (rc < 0) {
rc = 0;
@@ -357,6 +358,8 @@ out_unlock_msg_ctx:
out_unlock_daemon:
daemon->flags &= ~ECRYPTFS_DAEMON_IN_READ;
mutex_unlock(&daemon->mux);
+ if (mutex_is_locked(&ecryptfs_daemon_hash_mux))
+ mutex_unlock(&ecryptfs_daemon_hash_mux);
return rc;
}
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] eCryptFS: mutex lock-unlock ordering fix
2008-05-20 16:39 [PATCH] eCryptFS: mutex lock-unlock ordering fix Cyrill Gorcunov
@ 2008-05-20 16:42 ` Cyrill Gorcunov
0 siblings, 0 replies; 2+ messages in thread
From: Cyrill Gorcunov @ 2008-05-20 16:42 UTC (permalink / raw)
To: Michael A. Halcrow, Andrew Morton, Ingo Molnar, LKML
[Cyrill Gorcunov - Tue, May 20, 2008 at 08:39:28PM +0400]
| We should lock/unlock mutexes by a proper way which means
| there should not be chains like ABAB but ABBA otherwise the
| race window is opened.
|
| Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
| CC: Michael A. Halcrow <mhalcrow@us.ibm.com>
| ---
|
| check_list:
[...]
| if (list_empty(&daemon->msg_ctx_out_queue)) {
NIT ---> | + if (mutex_is_locked(&ecryptfs_daemon_hash_mux))
| + mutex_unlock(&ecryptfs_daemon_hash_mux);
| mutex_unlock(&daemon->mux);
| - rc = wait_event_interruptible(
| - daemon->wait, !list_empty(&daemon->msg_ctx_out_queue));
| + rc = wait_event_interruptible(daemon->wait,
| + !list_empty(&daemon->msg_ctx_out_queue));
| mutex_lock(&daemon->mux);
| if (rc < 0) {
| rc = 0;
| @@ -357,6 +358,8 @@ out_unlock_msg_ctx:
| out_unlock_daemon:
| daemon->flags &= ~ECRYPTFS_DAEMON_IN_READ;
| mutex_unlock(&daemon->mux);
| + if (mutex_is_locked(&ecryptfs_daemon_hash_mux))
| + mutex_unlock(&ecryptfs_daemon_hash_mux);
| return rc;
| }
|
It's a bit wrong (could release mutex being ack'ed by another thread)
will fix - please DROP this patch. Sorry!
- Cyrill -
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-05-20 16:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-20 16:39 [PATCH] eCryptFS: mutex lock-unlock ordering fix Cyrill Gorcunov
2008-05-20 16:42 ` Cyrill Gorcunov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox