Commit d3cfd5b9 authored by Elena Reshetova's avatar Elena Reshetova Committed by Greg Kroah-Hartman

drivers: convert vme_user_vma_priv.refcnt from atomic_t to refcount_t

refcount_t type and corresponding API should be
used instead of atomic_t when the variable is used as
a reference counter. This allows to avoid accidental
refcounter overflows that might lead to use-after-free
situations.
Signed-off-by: default avatarElena Reshetova <elena.reshetova@intel.com>
Signed-off-by: default avatarHans Liljestrand <ishkamiel@gmail.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarDavid Windsor <dwindsor@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 6a386dd0
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/atomic.h> #include <linux/refcount.h>
#include <linux/cdev.h> #include <linux/cdev.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/device.h> #include <linux/device.h>
...@@ -118,7 +118,7 @@ static const int type[VME_DEVS] = { MASTER_MINOR, MASTER_MINOR, ...@@ -118,7 +118,7 @@ static const int type[VME_DEVS] = { MASTER_MINOR, MASTER_MINOR,
struct vme_user_vma_priv { struct vme_user_vma_priv {
unsigned int minor; unsigned int minor;
atomic_t refcnt; refcount_t refcnt;
}; };
static ssize_t resource_to_user(int minor, char __user *buf, size_t count, static ssize_t resource_to_user(int minor, char __user *buf, size_t count,
...@@ -430,7 +430,7 @@ static void vme_user_vm_open(struct vm_area_struct *vma) ...@@ -430,7 +430,7 @@ static void vme_user_vm_open(struct vm_area_struct *vma)
{ {
struct vme_user_vma_priv *vma_priv = vma->vm_private_data; struct vme_user_vma_priv *vma_priv = vma->vm_private_data;
atomic_inc(&vma_priv->refcnt); refcount_inc(&vma_priv->refcnt);
} }
static void vme_user_vm_close(struct vm_area_struct *vma) static void vme_user_vm_close(struct vm_area_struct *vma)
...@@ -438,7 +438,7 @@ static void vme_user_vm_close(struct vm_area_struct *vma) ...@@ -438,7 +438,7 @@ static void vme_user_vm_close(struct vm_area_struct *vma)
struct vme_user_vma_priv *vma_priv = vma->vm_private_data; struct vme_user_vma_priv *vma_priv = vma->vm_private_data;
unsigned int minor = vma_priv->minor; unsigned int minor = vma_priv->minor;
if (!atomic_dec_and_test(&vma_priv->refcnt)) if (!refcount_dec_and_test(&vma_priv->refcnt))
return; return;
mutex_lock(&image[minor].mutex); mutex_lock(&image[minor].mutex);
...@@ -473,7 +473,7 @@ static int vme_user_master_mmap(unsigned int minor, struct vm_area_struct *vma) ...@@ -473,7 +473,7 @@ static int vme_user_master_mmap(unsigned int minor, struct vm_area_struct *vma)
} }
vma_priv->minor = minor; vma_priv->minor = minor;
atomic_set(&vma_priv->refcnt, 1); refcount_set(&vma_priv->refcnt, 1);
vma->vm_ops = &vme_user_vm_ops; vma->vm_ops = &vme_user_vm_ops;
vma->vm_private_data = vma_priv; vma->vm_private_data = vma_priv;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment