mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
Fix race between getf() and areleasef()
If a vnode is released asynchronously through areleasef(), it is possible for the user process to reuse the file descriptor before areleasef is called. When this happens, getf() will return a stale reference, any operations in the kernel on that file descriptor will fail (as it is closed) and the operations meant for that fd will never occur from userspace's perspective. We correct this by detecting this condition in getf(), doing a putf on the old file handle, updating the file descriptor and proceeding as if everything was fine. When the areleasef() is done, it will harmlessly decrement the reference counter on the Illumos file handle. Signed-off-by: Richard Yao <ryao@gentoo.org> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #492
This commit is contained in:
committed by
Brian Behlendorf
parent
d28c5c4f04
commit
1683e75edc
@@ -656,6 +656,19 @@ vn_getf(int fd)
|
||||
|
||||
fp = file_find(fd, current);
|
||||
if (fp) {
|
||||
lfp = fget(fd);
|
||||
fput(fp->f_file);
|
||||
/*
|
||||
* areleasef() can cause us to see a stale reference when
|
||||
* userspace has reused a file descriptor before areleasef()
|
||||
* has run. fput() the stale reference and replace it. We
|
||||
* retain the original reference count such that the concurrent
|
||||
* areleasef() will decrement its reference and terminate.
|
||||
*/
|
||||
if (lfp != fp->f_file) {
|
||||
fp->f_file = lfp;
|
||||
fp->f_vnode->v_file = lfp;
|
||||
}
|
||||
atomic_inc(&fp->f_ref);
|
||||
spin_unlock(&vn_file_lock);
|
||||
return (fp);
|
||||
|
||||
Reference in New Issue
Block a user