mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-17 02:15:57 +00:00
ceph: avoid use-after-free in ceph_fl_release_lock()
When ceph releasing the file_lock it will try to get the inode pointer from the fl->fl_file, which the memory could already be released by another thread in filp_close(). Because in VFS layer the fl->fl_file doesn't increase the file's reference counter. Will switch to use ceph dedicate lock info to track the inode. And in ceph_fl_release_lock() we should skip all the operations if the fl->fl_u.ceph.inode is not set, which should come from the request file_lock. And we will set fl->fl_u.ceph.inode when inserting it to the inode lock list, which is when copying the lock. Link: https://tracker.ceph.com/issues/57986 Signed-off-by: Xiubo Li <xiubli@redhat.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Reviewed-by: Ilya Dryomov <idryomov@gmail.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
This commit is contained in:
parent
461ab10ef7
commit
8e1858710d
@ -34,18 +34,34 @@ static void ceph_fl_copy_lock(struct file_lock *dst, struct file_lock *src)
|
|||||||
{
|
{
|
||||||
struct inode *inode = file_inode(dst->fl_file);
|
struct inode *inode = file_inode(dst->fl_file);
|
||||||
atomic_inc(&ceph_inode(inode)->i_filelock_ref);
|
atomic_inc(&ceph_inode(inode)->i_filelock_ref);
|
||||||
|
dst->fl_u.ceph.inode = igrab(inode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Do not use the 'fl->fl_file' in release function, which
|
||||||
|
* is possibly already released by another thread.
|
||||||
|
*/
|
||||||
static void ceph_fl_release_lock(struct file_lock *fl)
|
static void ceph_fl_release_lock(struct file_lock *fl)
|
||||||
{
|
{
|
||||||
struct inode *inode = file_inode(fl->fl_file);
|
struct inode *inode = fl->fl_u.ceph.inode;
|
||||||
struct ceph_inode_info *ci = ceph_inode(inode);
|
struct ceph_inode_info *ci;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If inode is NULL it should be a request file_lock,
|
||||||
|
* nothing we can do.
|
||||||
|
*/
|
||||||
|
if (!inode)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ci = ceph_inode(inode);
|
||||||
if (atomic_dec_and_test(&ci->i_filelock_ref)) {
|
if (atomic_dec_and_test(&ci->i_filelock_ref)) {
|
||||||
/* clear error when all locks are released */
|
/* clear error when all locks are released */
|
||||||
spin_lock(&ci->i_ceph_lock);
|
spin_lock(&ci->i_ceph_lock);
|
||||||
ci->i_ceph_flags &= ~CEPH_I_ERROR_FILELOCK;
|
ci->i_ceph_flags &= ~CEPH_I_ERROR_FILELOCK;
|
||||||
spin_unlock(&ci->i_ceph_lock);
|
spin_unlock(&ci->i_ceph_lock);
|
||||||
}
|
}
|
||||||
|
fl->fl_u.ceph.inode = NULL;
|
||||||
|
iput(inode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct file_lock_operations ceph_fl_lock_ops = {
|
static const struct file_lock_operations ceph_fl_lock_ops = {
|
||||||
|
@ -1119,6 +1119,9 @@ struct file_lock {
|
|||||||
int state; /* state of grant or error if -ve */
|
int state; /* state of grant or error if -ve */
|
||||||
unsigned int debug_id;
|
unsigned int debug_id;
|
||||||
} afs;
|
} afs;
|
||||||
|
struct {
|
||||||
|
struct inode *inode;
|
||||||
|
} ceph;
|
||||||
} fl_u;
|
} fl_u;
|
||||||
} __randomize_layout;
|
} __randomize_layout;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user