Re: [PATCH] eCryptFS: mutex lock-unlock ordering fix

From: Cyrill Gorcunov
Date: Tue May 20 2008 - 12:42:39 EST


[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@xxxxxxxxx>
| CC: Michael A. Halcrow <mhalcrow@xxxxxxxxxx>
| ---
|
| 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 -
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/