]> git.baikalelectronics.ru Git - kernel.git/commit
iommu: Check if group is NULL before remove device
authorFrank Wunderlich <frank-w@public-files.de>
Sat, 31 Jul 2021 07:47:37 +0000 (09:47 +0200)
committerJoerg Roedel <jroedel@suse.de>
Mon, 2 Aug 2021 14:22:00 +0000 (16:22 +0200)
commit208adab36240d789af77ac75d6133fb5b61c1b4c
treee6dbfb30dfa120b3783d2d49fcad406f744830df
parent785ceb3f6212dfd2d90acb4777ec6c46c691a795
iommu: Check if group is NULL before remove device

If probe_device is failing, iommu_group is not initialized because
iommu_group_add_device is not reached, so freeing it will result
in NULL pointer access.

iommu_bus_init
  ->bus_iommu_probe
      ->probe_iommu_group in for each:/* return -22 in fail case */
          ->iommu_probe_device
              ->__iommu_probe_device       /* return -22 here.*/
                  -> ops->probe_device          /* return -22 here.*/
                  -> iommu_group_get_for_dev
                        -> ops->device_group
                        -> iommu_group_add_device //good case
  ->remove_iommu_group  //in fail case, it will remove group
     ->iommu_release_device
         ->iommu_group_remove_device // here we don't have group

In my case ops->probe_device (mtk_iommu_probe_device from
mtk_iommu_v1.c) is due to failing fwspec->ops mismatch.

Fixes: a2a3060edfdd ("iommu: IOMMU Groups")
Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
Link: https://lore.kernel.org/r/20210731074737.4573-1-linux@fw-web.de
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/iommu.c