Skip to content

Commit ab50cb9

Browse files
zhou1615alexdeucher
authored andcommitted
drm/radeon/radeon_kms: Fix a NULL pointer dereference in radeon_driver_open_kms()
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: cc9e67e ("drm/radeon: fix VM IB handling") Reviewed-by: Christian König <[email protected]> Signed-off-by: Zhou Qingyang <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 69cb562 commit ab50cb9

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

drivers/gpu/drm/radeon/radeon_kms.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,8 @@ void radeon_driver_lastclose_kms(struct drm_device *dev)
648648
int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
649649
{
650650
struct radeon_device *rdev = dev->dev_private;
651+
struct radeon_fpriv *fpriv;
652+
struct radeon_vm *vm;
651653
int r;
652654

653655
file_priv->driver_priv = NULL;
@@ -660,8 +662,6 @@ int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
660662

661663
/* new gpu have virtual address space support */
662664
if (rdev->family >= CHIP_CAYMAN) {
663-
struct radeon_fpriv *fpriv;
664-
struct radeon_vm *vm;
665665

666666
fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL);
667667
if (unlikely(!fpriv)) {
@@ -672,35 +672,39 @@ int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
672672
if (rdev->accel_working) {
673673
vm = &fpriv->vm;
674674
r = radeon_vm_init(rdev, vm);
675-
if (r) {
676-
kfree(fpriv);
677-
goto out_suspend;
678-
}
675+
if (r)
676+
goto out_fpriv;
679677

680678
r = radeon_bo_reserve(rdev->ring_tmp_bo.bo, false);
681-
if (r) {
682-
radeon_vm_fini(rdev, vm);
683-
kfree(fpriv);
684-
goto out_suspend;
685-
}
679+
if (r)
680+
goto out_vm_fini;
686681

687682
/* map the ib pool buffer read only into
688683
* virtual address space */
689684
vm->ib_bo_va = radeon_vm_bo_add(rdev, vm,
690685
rdev->ring_tmp_bo.bo);
686+
if (!vm->ib_bo_va) {
687+
r = -ENOMEM;
688+
goto out_vm_fini;
689+
}
690+
691691
r = radeon_vm_bo_set_addr(rdev, vm->ib_bo_va,
692692
RADEON_VA_IB_OFFSET,
693693
RADEON_VM_PAGE_READABLE |
694694
RADEON_VM_PAGE_SNOOPED);
695-
if (r) {
696-
radeon_vm_fini(rdev, vm);
697-
kfree(fpriv);
698-
goto out_suspend;
699-
}
695+
if (r)
696+
goto out_vm_fini;
700697
}
701698
file_priv->driver_priv = fpriv;
702699
}
703700

701+
if (!r)
702+
goto out_suspend;
703+
704+
out_vm_fini:
705+
radeon_vm_fini(rdev, vm);
706+
out_fpriv:
707+
kfree(fpriv);
704708
out_suspend:
705709
pm_runtime_mark_last_busy(dev->dev);
706710
pm_runtime_put_autosuspend(dev->dev);

0 commit comments

Comments
 (0)