Skip to content

Commit 15a2015

Browse files
committed
ceph: fix iput race when queueing inode work
If we queue a work item that calls iput(), make sure we ihold() before attempting to queue work. Otherwise our queued work might miraculously run before we notice the queue_work() succeeded and call ihold(), allowing the inode to be destroyed. That is, instead of if (queue_work(...)) ihold(); we need to do ihold(); if (!queue_work(...)) iput(); Reported-by: Amon Ott <a.ott@m-privacy.de> Signed-off-by: Sage Weil <sage@newdream.net>
1 parent 0c6d4b4 commit 15a2015

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎fs/ceph/inode.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,12 +1328,13 @@ int ceph_inode_set_size(struct inode *inode, loff_t size)
13281328
*/
13291329
void ceph_queue_writeback(struct inode *inode)
13301330
{
1331+
ihold(inode);
13311332
if (queue_work(ceph_inode_to_client(inode)->wb_wq,
13321333
&ceph_inode(inode)->i_wb_work)) {
13331334
dout("ceph_queue_writeback %p\n", inode);
1334-
ihold(inode);
13351335
} else {
13361336
dout("ceph_queue_writeback %p failed\n", inode);
1337+
iput(inode);
13371338
}
13381339
}
13391340

@@ -1353,12 +1354,13 @@ static void ceph_writeback_work(struct work_struct *work)
13531354
*/
13541355
void ceph_queue_invalidate(struct inode *inode)
13551356
{
1357+
ihold(inode);
13561358
if (queue_work(ceph_inode_to_client(inode)->pg_inv_wq,
13571359
&ceph_inode(inode)->i_pg_inv_work)) {
13581360
dout("ceph_queue_invalidate %p\n", inode);
1359-
ihold(inode);
13601361
} else {
13611362
dout("ceph_queue_invalidate %p failed\n", inode);
1363+
iput(inode);
13621364
}
13631365
}
13641366

@@ -1434,13 +1436,14 @@ void ceph_queue_vmtruncate(struct inode *inode)
14341436
{
14351437
struct ceph_inode_info *ci = ceph_inode(inode);
14361438

1439+
ihold(inode);
14371440
if (queue_work(ceph_sb_to_client(inode->i_sb)->trunc_wq,
14381441
&ci->i_vmtruncate_work)) {
14391442
dout("ceph_queue_vmtruncate %p\n", inode);
1440-
ihold(inode);
14411443
} else {
14421444
dout("ceph_queue_vmtruncate %p failed, pending=%d\n",
14431445
inode, ci->i_truncate_pending);
1446+
iput(inode);
14441447
}
14451448
}
14461449

0 commit comments

Comments
 (0)