Skip to content

Commit 60d65f1

Browse files
committed
eCryptfs: Fix lockdep warning in miscdev operations
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 <[email protected]>
1 parent 9fe79d7 commit 60d65f1

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

fs/ecryptfs/miscdev.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,31 +191,32 @@ int ecryptfs_send_miscdev(char *data, size_t data_size,
191191
struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type,
192192
u16 msg_flags, struct ecryptfs_daemon *daemon)
193193
{
194-
int rc = 0;
194+
struct ecryptfs_message *msg;
195195

196-
mutex_lock(&msg_ctx->mux);
197-
msg_ctx->msg = kmalloc((sizeof(*msg_ctx->msg) + data_size),
198-
GFP_KERNEL);
199-
if (!msg_ctx->msg) {
200-
rc = -ENOMEM;
196+
msg = kmalloc((sizeof(*msg) + data_size), GFP_KERNEL);
197+
if (!msg) {
201198
printk(KERN_ERR "%s: Out of memory whilst attempting "
202199
"to kmalloc(%zd, GFP_KERNEL)\n", __func__,
203-
(sizeof(*msg_ctx->msg) + data_size));
204-
goto out_unlock;
200+
(sizeof(*msg) + data_size));
201+
return -ENOMEM;
205202
}
203+
204+
mutex_lock(&msg_ctx->mux);
205+
msg_ctx->msg = msg;
206206
msg_ctx->msg->index = msg_ctx->index;
207207
msg_ctx->msg->data_len = data_size;
208208
msg_ctx->type = msg_type;
209209
memcpy(msg_ctx->msg->data, data, data_size);
210210
msg_ctx->msg_size = (sizeof(*msg_ctx->msg) + data_size);
211-
mutex_lock(&daemon->mux);
212211
list_add_tail(&msg_ctx->daemon_out_list, &daemon->msg_ctx_out_queue);
212+
mutex_unlock(&msg_ctx->mux);
213+
214+
mutex_lock(&daemon->mux);
213215
daemon->num_queued_msg_ctx++;
214216
wake_up_interruptible(&daemon->wait);
215217
mutex_unlock(&daemon->mux);
216-
out_unlock:
217-
mutex_unlock(&msg_ctx->mux);
218-
return rc;
218+
219+
return 0;
219220
}
220221

221222
/*

0 commit comments

Comments
 (0)