[PATCH] sanitize anon_inode_getfd()

a) none of the callers even looks at inode or file returned by anon_inode_getfd()
b) any caller that would try to look at those would be racy, since by the time
it returns we might have raced with close() from another thread and that
file would be pining for fjords.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
这个提交包含在:
Al Viro
2008-02-23 06:46:49 -05:00
父节点 9f3acc3140
当前提交 2030a42cec
修改 7 个文件,包含 29 行新增74 行删除

查看文件

@@ -834,16 +834,9 @@ static const struct file_operations kvm_vcpu_fops = {
*/
static int create_vcpu_fd(struct kvm_vcpu *vcpu)
{
int fd, r;
struct inode *inode;
struct file *file;
r = anon_inode_getfd(&fd, &inode, &file,
"kvm-vcpu", &kvm_vcpu_fops, vcpu);
if (r) {
int fd = anon_inode_getfd("kvm-vcpu", &kvm_vcpu_fops, vcpu);
if (fd < 0)
kvm_put_kvm(vcpu->kvm);
return r;
}
return fd;
}
@@ -1168,19 +1161,15 @@ static const struct file_operations kvm_vm_fops = {
static int kvm_dev_ioctl_create_vm(void)
{
int fd, r;
struct inode *inode;
struct file *file;
int fd;
struct kvm *kvm;
kvm = kvm_create_vm();
if (IS_ERR(kvm))
return PTR_ERR(kvm);
r = anon_inode_getfd(&fd, &inode, &file, "kvm-vm", &kvm_vm_fops, kvm);
if (r) {
fd = anon_inode_getfd("kvm-vm", &kvm_vm_fops, kvm);
if (fd < 0)
kvm_put_kvm(kvm);
return r;
}
return fd;
}