Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2891720pxb; Tue, 24 Aug 2021 10:00:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVZCBPlvs/lCG1A8XWrI5KDtuO5jXi1jELNq6O5u2aDCRIIMANqi3pe4bMPoVQKOw00KK8 X-Received: by 2002:a92:cccf:: with SMTP id u15mr29093352ilq.144.1629824413443; Tue, 24 Aug 2021 10:00:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629824413; cv=none; d=google.com; s=arc-20160816; b=O08T4YqCRL3fOAklHeVIetnXN0ejpYYw6XM+BgRWUGfcSkub7LzKaJaXzD+P64Lrb1 MTE/hs/j0NSVCywFnkJ/neOswQJYCUSVYM/HSaPlN0tQSqIfoT0M9JoIipN+4zbeEVRd XitzMX553shlaE+0cBh62I+XuuJBQi36syfHcF10UuCS4vgF2RlbWxXKFzuxuA4m5C4A FYEeTBVELDx8QxbyYhSQfskfioLALh0rJwGKVvFDqr408583/7jylkDpfZwH2KTseSF2 ZOCcHw9aLf6KppsqpeBw/aH9WcJ8uojlO9dukddVmlmZr6kPbgPtY2A5B5QSzhNAtQtb QjLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5sP4Bt+Cy4haTqFNtYxPCIl0nGpyhZ3tIDxtEKawvlM=; b=u1vIKB1ZbRfmROAkwTTjn0rOwUfxuEeS6tzskMctpHKIxXo6oDDHHyyUQ/dez+x1QC JH+SsbVfQAIYTRP35gy81afBIAhpxLsMCkUEaq1uMPkHVMBmKZrG5lIXNg5J6ZcNSNgZ uWWHKCJB4SeINYAeTxyEmmzW9LioFiMHZaxNZiwn5ICxhUAJllf4LAaW3zg9SFrbmc06 odUfcIhe7fbVXDJjkTTy0G49HpUoG9p2cz4RTjcwVjhA7BApu2vRFEIc3x6wjvIenUIH lULPegzL3+zWT14YNIpMhH3OIaaj7tw7MVRGWw3PXoFdwHWc1GwCltDcK3hUpCUkTP3u zmCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kkFPxt0n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b3si18106292ile.20.2021.08.24.09.59.59; Tue, 24 Aug 2021 10:00:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kkFPxt0n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234587AbhHXQ61 (ORCPT + 99 others); Tue, 24 Aug 2021 12:58:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:39104 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234670AbhHXQ5W (ORCPT ); Tue, 24 Aug 2021 12:57:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 860B5613AD; Tue, 24 Aug 2021 16:56:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824198; bh=ZVZuKs6XUn6BAkfA0tatcEsqam+Mrf7MKtSUxlWRcXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kkFPxt0nXoDywSod787u+qvOCKhDTGcJVrZEB246uE67HmJpE5YvQbeuVmuslAVgf o3o3lyxbdP90DJYEW1RqT5L5acio72ZwaWmGgfjNaW39kqvYGDZKNkOsC+MruE8UJ6 jlsKEcvFgCrUpxS8tUIUQRAu8mqWYZQ2wqUFk45Qj1GhpvOg7yDSYqGX1F65piWPr5 lLdFqdB7FNjlZ/FwxkyDqJQ4rHF2usLnSKVy1fpOFVWSuUm9Fk+StCnpRxjySLHU9g LPboCRHLM4k7JZLbnUelyuNTQ1OTtL2oEiP3EWsuKRkCDeFhdBWHT/WI3DpszImnxK TcfYg+u+zXHeQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Frank Wunderlich , Joerg Roedel , Sasha Levin Subject: [PATCH 5.13 030/127] iommu: Check if group is NULL before remove device Date: Tue, 24 Aug 2021 12:54:30 -0400 Message-Id: <20210824165607.709387-31-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824165607.709387-1-sashal@kernel.org> References: <20210824165607.709387-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.13.13-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.13.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.13.13-rc1 X-KernelTest-Deadline: 2021-08-26T16:55+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Frank Wunderlich [ Upstream commit 5aa95d8834e07907e64937d792c12ffef7fb271f ] 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: d72e31c93746 ("iommu: IOMMU Groups") Signed-off-by: Frank Wunderlich Link: https://lore.kernel.org/r/20210731074737.4573-1-linux@fw-web.de Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/iommu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 808ab70d5df5..db966a7841fe 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -924,6 +924,9 @@ void iommu_group_remove_device(struct device *dev) struct iommu_group *group = dev->iommu_group; struct group_device *tmp_device, *device = NULL; + if (!group) + return; + dev_info(dev, "Removing from iommu group %d\n", group->id); /* Pre-notify listeners that a device is being removed. */ -- 2.30.2