All of lore.kernel.org
 help / color / mirror / Atom feed
* [bug report] KVM: Introduce a 'release' method for KVM devices
@ 2019-05-02  7:03 Dan Carpenter
  2019-05-02  7:09 ` Alexey Kardashevskiy
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2019-05-02  7:03 UTC (permalink / raw)
  To: clg; +Cc: kvm

Hello Cédric Le Goater,

This is a semi-automatic email about new static checker warnings.

The patch 2bde9b3ec8bd: "KVM: Introduce a 'release' method for KVM 
devices" from Apr 18, 2019, leads to the following Smatch complaint:

    arch/x86/kvm/../../../virt/kvm/kvm_main.c:2943 kvm_device_release()
    warn: variable dereferenced before check 'dev' (see line 2941)

arch/x86/kvm/../../../virt/kvm/kvm_main.c
  2938  static int kvm_device_release(struct inode *inode, struct file *filp)
  2939  {
  2940		struct kvm_device *dev = filp->private_data;
  2941		struct kvm *kvm = dev->kvm;
                                  ^^^^^^^^
Dereference.

  2942	
  2943		if (!dev)
                    ^^^^
Checked too late.

  2944			return -ENODEV;
  2945	
  2946          if (dev->kvm != kvm)
                    ^^^^^^^^^^^^^^^
What is this testing?  We just set "kvm = dev->kvm;" at the start.

  2947                  return -EPERM;
  2948  
  2949          if (dev->ops->release) {
  2950                  mutex_lock(&kvm->lock);
  2951                  list_del(&dev->vm_node);
  2952                  dev->ops->release(dev);
  2953                  mutex_unlock(&kvm->lock);
  2954          }
  2955  
  2956          kvm_put_kvm(kvm);
  2957          return 0;
  2958  }

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [bug report] KVM: Introduce a 'release' method for KVM devices
  2019-05-02  7:03 [bug report] KVM: Introduce a 'release' method for KVM devices Dan Carpenter
@ 2019-05-02  7:09 ` Alexey Kardashevskiy
  0 siblings, 0 replies; 2+ messages in thread
From: Alexey Kardashevskiy @ 2019-05-02  7:09 UTC (permalink / raw)
  To: Dan Carpenter, clg; +Cc: kvm



On 02/05/2019 17:03, Dan Carpenter wrote:
> Hello Cédric Le Goater,
> 
> This is a semi-automatic email about new static checker warnings.
> 
> The patch 2bde9b3ec8bd: "KVM: Introduce a 'release' method for KVM 
> devices" from Apr 18, 2019, leads to the following Smatch complaint:


Already reported https://lkml.org/lkml/2019/5/1/235


> 
>     arch/x86/kvm/../../../virt/kvm/kvm_main.c:2943 kvm_device_release()
>     warn: variable dereferenced before check 'dev' (see line 2941)
> 
> arch/x86/kvm/../../../virt/kvm/kvm_main.c
>   2938  static int kvm_device_release(struct inode *inode, struct file *filp)
>   2939  {
>   2940		struct kvm_device *dev = filp->private_data;
>   2941		struct kvm *kvm = dev->kvm;
>                                   ^^^^^^^^
> Dereference.
> 
>   2942	
>   2943		if (!dev)
>                     ^^^^
> Checked too late.
> 
>   2944			return -ENODEV;
>   2945	
>   2946          if (dev->kvm != kvm)
>                     ^^^^^^^^^^^^^^^
> What is this testing?  We just set "kvm = dev->kvm;" at the start.
> 
>   2947                  return -EPERM;
>   2948  
>   2949          if (dev->ops->release) {
>   2950                  mutex_lock(&kvm->lock);
>   2951                  list_del(&dev->vm_node);
>   2952                  dev->ops->release(dev);
>   2953                  mutex_unlock(&kvm->lock);
>   2954          }
>   2955  
>   2956          kvm_put_kvm(kvm);
>   2957          return 0;
>   2958  }
> 
> regards,
> dan carpenter
> 

-- 
Alexey

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-05-02  7:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-02  7:03 [bug report] KVM: Introduce a 'release' method for KVM devices Dan Carpenter
2019-05-02  7:09 ` Alexey Kardashevskiy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.