mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-06 02:50:49 +09:00
ceph: fix use-after-free bug for inodes when flushing capsnaps
commit 409e873ea3 upstream.
There is a race between capsnaps flush and removing the inode from
'mdsc->snap_flush_list' list:
== Thread A == == Thread B ==
ceph_queue_cap_snap()
-> allocate 'capsnapA'
->ihold('&ci->vfs_inode')
->add 'capsnapA' to 'ci->i_cap_snaps'
->add 'ci' to 'mdsc->snap_flush_list'
...
== Thread C ==
ceph_flush_snaps()
->__ceph_flush_snaps()
->__send_flush_snap()
handle_cap_flushsnap_ack()
->iput('&ci->vfs_inode')
this also will release 'ci'
...
== Thread D ==
ceph_handle_snap()
->flush_snaps()
->iterate 'mdsc->snap_flush_list'
->get the stale 'ci'
->remove 'ci' from ->ihold(&ci->vfs_inode) this
'mdsc->snap_flush_list' will WARNING
To fix this we will increase the inode's i_count ref when adding 'ci'
to the 'mdsc->snap_flush_list' list.
[ idryomov: need_put int -> bool ]
Cc: stable@vger.kernel.org
Link: https://bugzilla.redhat.com/show_bug.cgi?id=2209299
Signed-off-by: Xiubo Li <xiubli@redhat.com>
Reviewed-by: Milind Changire <mchangir@redhat.com>
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
6714873158
commit
e715c86e92
@@ -1636,6 +1636,7 @@ void ceph_flush_snaps(struct ceph_inode_info *ci,
|
|||||||
struct inode *inode = &ci->vfs_inode;
|
struct inode *inode = &ci->vfs_inode;
|
||||||
struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc;
|
struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc;
|
||||||
struct ceph_mds_session *session = NULL;
|
struct ceph_mds_session *session = NULL;
|
||||||
|
bool need_put = false;
|
||||||
int mds;
|
int mds;
|
||||||
|
|
||||||
dout("ceph_flush_snaps %p\n", inode);
|
dout("ceph_flush_snaps %p\n", inode);
|
||||||
@@ -1687,8 +1688,13 @@ out:
|
|||||||
}
|
}
|
||||||
/* we flushed them all; remove this inode from the queue */
|
/* we flushed them all; remove this inode from the queue */
|
||||||
spin_lock(&mdsc->snap_flush_lock);
|
spin_lock(&mdsc->snap_flush_lock);
|
||||||
|
if (!list_empty(&ci->i_snap_flush_item))
|
||||||
|
need_put = true;
|
||||||
list_del_init(&ci->i_snap_flush_item);
|
list_del_init(&ci->i_snap_flush_item);
|
||||||
spin_unlock(&mdsc->snap_flush_lock);
|
spin_unlock(&mdsc->snap_flush_lock);
|
||||||
|
|
||||||
|
if (need_put)
|
||||||
|
iput(inode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -647,8 +647,10 @@ int __ceph_finish_cap_snap(struct ceph_inode_info *ci,
|
|||||||
capsnap->size);
|
capsnap->size);
|
||||||
|
|
||||||
spin_lock(&mdsc->snap_flush_lock);
|
spin_lock(&mdsc->snap_flush_lock);
|
||||||
if (list_empty(&ci->i_snap_flush_item))
|
if (list_empty(&ci->i_snap_flush_item)) {
|
||||||
|
ihold(inode);
|
||||||
list_add_tail(&ci->i_snap_flush_item, &mdsc->snap_flush_list);
|
list_add_tail(&ci->i_snap_flush_item, &mdsc->snap_flush_list);
|
||||||
|
}
|
||||||
spin_unlock(&mdsc->snap_flush_lock);
|
spin_unlock(&mdsc->snap_flush_lock);
|
||||||
return 1; /* caller may want to ceph_flush_snaps */
|
return 1; /* caller may want to ceph_flush_snaps */
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user