diff options
author | Tyler Hicks <tyhicks@canonical.com> | 2012-06-11 13:21:34 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-07-16 11:47:49 -0400 |
commit | 092c1927ef479124a34fcf0646cf5c403f9b16e5 (patch) | |
tree | 11b6c78bf9c4259cbaa778a2cf37e06686039211 /fs | |
parent | 542b7a372e617cf3db2f659378e1ed3342fdc31b (diff) |
eCryptfs: Fix lockdep warning in miscdev operations
commit 60d65f1f07a7d81d3eb3b91fc13fca80f2fdbb12 upstream.
Don't grab the daemon mutex while holding the message context mutex.
Addresses this lockdep warning:
ecryptfsd/2141 is trying to acquire lock:
(&ecryptfs_msg_ctx_arr[i].mux){+.+.+.}, at: [<ffffffffa029c213>] ecryptfs_miscdev_read+0x143/0x470 [ecryptfs]
but task is already holding lock:
(&(*daemon)->mux){+.+...}, at: [<ffffffffa029c2ec>] ecryptfs_miscdev_read+0x21c/0x470 [ecryptfs]
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #1 (&(*daemon)->mux){+.+...}:
[<ffffffff810a3b8d>] lock_acquire+0x9d/0x220
[<ffffffff8151c6da>] __mutex_lock_common+0x5a/0x4b0
[<ffffffff8151cc64>] mutex_lock_nested+0x44/0x50
[<ffffffffa029c5d7>] ecryptfs_send_miscdev+0x97/0x120 [ecryptfs]
[<ffffffffa029b744>] ecryptfs_send_message+0x134/0x1e0 [ecryptfs]
[<ffffffffa029a24e>] ecryptfs_generate_key_packet_set+0x2fe/0xa80 [ecryptfs]
[<ffffffffa02960f8>] ecryptfs_write_metadata+0x108/0x250 [ecryptfs]
[<ffffffffa0290f80>] ecryptfs_create+0x130/0x250 [ecryptfs]
[<ffffffff811963a4>] vfs_create+0xb4/0x120
[<ffffffff81197865>] do_last+0x8c5/0xa10
[<ffffffff811998f9>] path_openat+0xd9/0x460
[<ffffffff81199da2>] do_filp_open+0x42/0xa0
[<ffffffff81187998>] do_sys_open+0xf8/0x1d0
[<ffffffff81187a91>] sys_open+0x21/0x30
[<ffffffff81527d69>] system_call_fastpath+0x16/0x1b
-> #0 (&ecryptfs_msg_ctx_arr[i].mux){+.+.+.}:
[<ffffffff810a3418>] __lock_acquire+0x1bf8/0x1c50
[<ffffffff810a3b8d>] lock_acquire+0x9d/0x220
[<ffffffff8151c6da>] __mutex_lock_common+0x5a/0x4b0
[<ffffffff8151cc64>] mutex_lock_nested+0x44/0x50
[<ffffffffa029c213>] ecryptfs_miscdev_read+0x143/0x470 [ecryptfs]
[<ffffffff811887d3>] vfs_read+0xb3/0x180
[<ffffffff811888ed>] sys_read+0x4d/0x90
[<ffffffff81527d69>] system_call_fastpath+0x16/0x1b
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ecryptfs/miscdev.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c index a050e4bad9a..de42310cd4f 100644 --- a/fs/ecryptfs/miscdev.c +++ b/fs/ecryptfs/miscdev.c | |||
@@ -195,31 +195,32 @@ int ecryptfs_send_miscdev(char *data, size_t data_size, | |||
195 | struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type, | 195 | struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type, |
196 | u16 msg_flags, struct ecryptfs_daemon *daemon) | 196 | u16 msg_flags, struct ecryptfs_daemon *daemon) |
197 | { | 197 | { |
198 | int rc = 0; | 198 | struct ecryptfs_message *msg; |
199 | 199 | ||
200 | mutex_lock(&msg_ctx->mux); | 200 | msg = kmalloc((sizeof(*msg) + data_size), GFP_KERNEL); |
201 | msg_ctx->msg = kmalloc((sizeof(*msg_ctx->msg) + data_size), | 201 | if (!msg) { |
202 | GFP_KERNEL); | ||
203 | if (!msg_ctx->msg) { | ||
204 | rc = -ENOMEM; | ||
205 | printk(KERN_ERR "%s: Out of memory whilst attempting " | 202 | printk(KERN_ERR "%s: Out of memory whilst attempting " |
206 | "to kmalloc(%zd, GFP_KERNEL)\n", __func__, | 203 | "to kmalloc(%zd, GFP_KERNEL)\n", __func__, |
207 | (sizeof(*msg_ctx->msg) + data_size)); | 204 | (sizeof(*msg) + data_size)); |
208 | goto out_unlock; | 205 | return -ENOMEM; |
209 | } | 206 | } |
207 | |||
208 | mutex_lock(&msg_ctx->mux); | ||
209 | msg_ctx->msg = msg; | ||
210 | msg_ctx->msg->index = msg_ctx->index; | 210 | msg_ctx->msg->index = msg_ctx->index; |
211 | msg_ctx->msg->data_len = data_size; | 211 | msg_ctx->msg->data_len = data_size; |
212 | msg_ctx->type = msg_type; | 212 | msg_ctx->type = msg_type; |
213 | memcpy(msg_ctx->msg->data, data, data_size); | 213 | memcpy(msg_ctx->msg->data, data, data_size); |
214 | msg_ctx->msg_size = (sizeof(*msg_ctx->msg) + data_size); | 214 | msg_ctx->msg_size = (sizeof(*msg_ctx->msg) + data_size); |
215 | mutex_lock(&daemon->mux); | ||
216 | list_add_tail(&msg_ctx->daemon_out_list, &daemon->msg_ctx_out_queue); | 215 | list_add_tail(&msg_ctx->daemon_out_list, &daemon->msg_ctx_out_queue); |
216 | mutex_unlock(&msg_ctx->mux); | ||
217 | |||
218 | mutex_lock(&daemon->mux); | ||
217 | daemon->num_queued_msg_ctx++; | 219 | daemon->num_queued_msg_ctx++; |
218 | wake_up_interruptible(&daemon->wait); | 220 | wake_up_interruptible(&daemon->wait); |
219 | mutex_unlock(&daemon->mux); | 221 | mutex_unlock(&daemon->mux); |
220 | out_unlock: | 222 | |
221 | mutex_unlock(&msg_ctx->mux); | 223 | return 0; |
222 | return rc; | ||
223 | } | 224 | } |
224 | 225 | ||
225 | /** | 226 | /** |