提交 4383d541 编写于 作者: Z Zhou Qingyang 提交者: Zheng Zengkai

drm/radeon/radeon_kms: Fix a NULL pointer dereference in radeon_driver_open_kms()

stable inclusion
from stable-v5.10.94
commit f277978d6c463942e1bd0137053f74ae4d6892af
bugzilla: https://gitee.com/openeuler/kernel/issues/I531X9

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=f277978d6c463942e1bd0137053f74ae4d6892af

--------------------------------

[ Upstream commit ab50cb9d ]

In radeon_driver_open_kms(), radeon_vm_bo_add() is assigned to
vm->ib_bo_va and passes and used in radeon_vm_bo_set_addr(). In
radeon_vm_bo_set_addr(), there is a dereference of vm->ib_bo_va,
which could lead to a NULL pointer dereference on failure of
radeon_vm_bo_add().

Fix this bug by adding a check of vm->ib_bo_va.

This bug was found by a static analyzer. The analysis employs
differential checking to identify inconsistent security operations
(e.g., checks or kfrees) between two code paths and confirms that the
inconsistent operations are not recovered in the current function or
the callers, so they constitute bugs.

Note that, as a bug found by static analysis, it can be a false
positive or hard to trigger. Multiple researchers have cross-reviewed
the bug.

Builds with CONFIG_DRM_RADEON=m show no new warnings,
and our static analyzer no longer warns about this code.

Fixes: cc9e67e3 ("drm/radeon: fix VM IB handling")
Reviewed-by: NChristian König <christian.koenig@amd.com>
Signed-off-by: NZhou Qingyang <zhou1615@umn.edu>
Signed-off-by: NAlex Deucher <alexander.deucher@amd.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
上级 cb451fc7
...@@ -634,6 +634,8 @@ void radeon_driver_lastclose_kms(struct drm_device *dev) ...@@ -634,6 +634,8 @@ void radeon_driver_lastclose_kms(struct drm_device *dev)
int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
{ {
struct radeon_device *rdev = dev->dev_private; struct radeon_device *rdev = dev->dev_private;
struct radeon_fpriv *fpriv;
struct radeon_vm *vm;
int r; int r;
file_priv->driver_priv = NULL; file_priv->driver_priv = NULL;
...@@ -646,8 +648,6 @@ int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) ...@@ -646,8 +648,6 @@ int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
/* new gpu have virtual address space support */ /* new gpu have virtual address space support */
if (rdev->family >= CHIP_CAYMAN) { if (rdev->family >= CHIP_CAYMAN) {
struct radeon_fpriv *fpriv;
struct radeon_vm *vm;
fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL); fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL);
if (unlikely(!fpriv)) { if (unlikely(!fpriv)) {
...@@ -658,35 +658,39 @@ int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) ...@@ -658,35 +658,39 @@ int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
if (rdev->accel_working) { if (rdev->accel_working) {
vm = &fpriv->vm; vm = &fpriv->vm;
r = radeon_vm_init(rdev, vm); r = radeon_vm_init(rdev, vm);
if (r) { if (r)
kfree(fpriv); goto out_fpriv;
goto out_suspend;
}
r = radeon_bo_reserve(rdev->ring_tmp_bo.bo, false); r = radeon_bo_reserve(rdev->ring_tmp_bo.bo, false);
if (r) { if (r)
radeon_vm_fini(rdev, vm); goto out_vm_fini;
kfree(fpriv);
goto out_suspend;
}
/* map the ib pool buffer read only into /* map the ib pool buffer read only into
* virtual address space */ * virtual address space */
vm->ib_bo_va = radeon_vm_bo_add(rdev, vm, vm->ib_bo_va = radeon_vm_bo_add(rdev, vm,
rdev->ring_tmp_bo.bo); rdev->ring_tmp_bo.bo);
if (!vm->ib_bo_va) {
r = -ENOMEM;
goto out_vm_fini;
}
r = radeon_vm_bo_set_addr(rdev, vm->ib_bo_va, r = radeon_vm_bo_set_addr(rdev, vm->ib_bo_va,
RADEON_VA_IB_OFFSET, RADEON_VA_IB_OFFSET,
RADEON_VM_PAGE_READABLE | RADEON_VM_PAGE_READABLE |
RADEON_VM_PAGE_SNOOPED); RADEON_VM_PAGE_SNOOPED);
if (r) { if (r)
radeon_vm_fini(rdev, vm); goto out_vm_fini;
kfree(fpriv);
goto out_suspend;
}
} }
file_priv->driver_priv = fpriv; file_priv->driver_priv = fpriv;
} }
if (!r)
goto out_suspend;
out_vm_fini:
radeon_vm_fini(rdev, vm);
out_fpriv:
kfree(fpriv);
out_suspend: out_suspend:
pm_runtime_mark_last_busy(dev->dev); pm_runtime_mark_last_busy(dev->dev);
pm_runtime_put_autosuspend(dev->dev); pm_runtime_put_autosuspend(dev->dev);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册