diff options
| author | YoungJun Cho <yj44.cho@samsung.com> | 2013-02-07 02:17:54 -0500 |
|---|---|---|
| committer | Inki Dae <inki.dae@samsung.com> | 2013-02-21 01:00:26 -0500 |
| commit | 5af9f116e6a0e1de675da979a19f95a74ce2aa2e (patch) | |
| tree | 987b13104c42dcb337a7f9654fbc8b6edac9e99e /drivers/gpu/drm | |
| parent | e44a5c00169df634c152bdba65c7b735eb3a7a81 (diff) | |
drm/exynos: fix wrong pointer access at vm close.
This patch fixes wrong pointer access issue to filp->f_op and
filp->private_data.
The exynos_drm_gem_mmap_ioctl() changes filp->f_op and
filp->private_data temporarily and restore them to use
original ones in exynos_drm_gem_mmap_buffer() but there
was no lock between the changing and the restoring so
wrong pointer access to filp->f_op and filp->private_data
was induced by vm close callback.
So this patch uses mutex lock properly to resolve this issue.
Signed-off-by: YoungJun Cho <yj44.cho@samsung.com>
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Diffstat (limited to 'drivers/gpu/drm')
| -rw-r--r-- | drivers/gpu/drm/exynos/exynos_drm_gem.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c b/drivers/gpu/drm/exynos/exynos_drm_gem.c index 473180776528..67e17ce112b6 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_gem.c +++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c | |||
| @@ -329,17 +329,11 @@ static struct drm_file *exynos_drm_find_drm_file(struct drm_device *drm_dev, | |||
| 329 | { | 329 | { |
| 330 | struct drm_file *file_priv; | 330 | struct drm_file *file_priv; |
| 331 | 331 | ||
| 332 | mutex_lock(&drm_dev->struct_mutex); | ||
| 333 | |||
| 334 | /* find current process's drm_file from filelist. */ | 332 | /* find current process's drm_file from filelist. */ |
| 335 | list_for_each_entry(file_priv, &drm_dev->filelist, lhead) { | 333 | list_for_each_entry(file_priv, &drm_dev->filelist, lhead) |
| 336 | if (file_priv->filp == filp) { | 334 | if (file_priv->filp == filp) |
| 337 | mutex_unlock(&drm_dev->struct_mutex); | ||
| 338 | return file_priv; | 335 | return file_priv; |
| 339 | } | ||
| 340 | } | ||
| 341 | 336 | ||
| 342 | mutex_unlock(&drm_dev->struct_mutex); | ||
| 343 | WARN_ON(1); | 337 | WARN_ON(1); |
| 344 | 338 | ||
| 345 | return ERR_PTR(-EFAULT); | 339 | return ERR_PTR(-EFAULT); |
| @@ -400,9 +394,7 @@ static int exynos_drm_gem_mmap_buffer(struct file *filp, | |||
| 400 | */ | 394 | */ |
| 401 | drm_gem_object_reference(obj); | 395 | drm_gem_object_reference(obj); |
| 402 | 396 | ||
| 403 | mutex_lock(&drm_dev->struct_mutex); | ||
| 404 | drm_vm_open_locked(drm_dev, vma); | 397 | drm_vm_open_locked(drm_dev, vma); |
| 405 | mutex_unlock(&drm_dev->struct_mutex); | ||
| 406 | 398 | ||
| 407 | return 0; | 399 | return 0; |
| 408 | } | 400 | } |
| @@ -432,6 +424,16 @@ int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data, | |||
| 432 | } | 424 | } |
| 433 | 425 | ||
| 434 | /* | 426 | /* |
| 427 | * We have to use gem object and its fops for specific mmaper, | ||
| 428 | * but vm_mmap() can deliver only filp. So we have to change | ||
| 429 | * filp->f_op and filp->private_data temporarily, then restore | ||
| 430 | * again. So it is important to keep lock until restoration the | ||
| 431 | * settings to prevent others from misuse of filp->f_op or | ||
| 432 | * filp->private_data. | ||
| 433 | */ | ||
| 434 | mutex_lock(&dev->struct_mutex); | ||
| 435 | |||
| 436 | /* | ||
| 435 | * Set specific mmper's fops. And it will be restored by | 437 | * Set specific mmper's fops. And it will be restored by |
| 436 | * exynos_drm_gem_mmap_buffer to dev->driver->fops. | 438 | * exynos_drm_gem_mmap_buffer to dev->driver->fops. |
| 437 | * This is used to call specific mapper temporarily. | 439 | * This is used to call specific mapper temporarily. |
| @@ -448,13 +450,20 @@ int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data, | |||
| 448 | addr = vm_mmap(file_priv->filp, 0, args->size, | 450 | addr = vm_mmap(file_priv->filp, 0, args->size, |
| 449 | PROT_READ | PROT_WRITE, MAP_SHARED, 0); | 451 | PROT_READ | PROT_WRITE, MAP_SHARED, 0); |
| 450 | 452 | ||
| 451 | drm_gem_object_unreference_unlocked(obj); | 453 | drm_gem_object_unreference(obj); |
| 452 | 454 | ||
| 453 | if (IS_ERR((void *)addr)) { | 455 | if (IS_ERR((void *)addr)) { |
| 454 | file_priv->filp->private_data = file_priv; | 456 | /* check filp->f_op, filp->private_data are restored */ |
| 457 | if (file_priv->filp->f_op == &exynos_drm_gem_fops) { | ||
| 458 | file_priv->filp->f_op = fops_get(dev->driver->fops); | ||
| 459 | file_priv->filp->private_data = file_priv; | ||
| 460 | } | ||
| 461 | mutex_unlock(&dev->struct_mutex); | ||
| 455 | return PTR_ERR((void *)addr); | 462 | return PTR_ERR((void *)addr); |
| 456 | } | 463 | } |
| 457 | 464 | ||
| 465 | mutex_unlock(&dev->struct_mutex); | ||
| 466 | |||
| 458 | args->mapped = addr; | 467 | args->mapped = addr; |
| 459 | 468 | ||
| 460 | DRM_DEBUG_KMS("mapped = 0x%lx\n", (unsigned long)args->mapped); | 469 | DRM_DEBUG_KMS("mapped = 0x%lx\n", (unsigned long)args->mapped); |
