Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp836025imu; Tue, 11 Dec 2018 08:17:35 -0800 (PST) X-Google-Smtp-Source: AFSGD/XVjFP8C8whO70Zc9YeT3ikgS8tQVU1T386d+Jfvq/XUw7xZnVcpPQuLNl1E+tPNvGiyPdS X-Received: by 2002:a62:f247:: with SMTP id y7mr16916556pfl.25.1544545055010; Tue, 11 Dec 2018 08:17:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544545054; cv=none; d=google.com; s=arc-20160816; b=FyGvfLAQ8LcK5Q9JdvwFy2MCYdSJWHOBflb/ZPgJVdHwAFFaTfpAISFTfjdntU+agC 6gFiKMtdiBcMkGvKzf0qYck/Ndt77ALnZrB7dd4L3jTy/7yyhPsM/deHz3GU+c+ip+6Z NgCWbUunOtd9SK65grbDY3trm2uiCSxRCr8sUPupf+Do2lZxKStT6ol2BPgNQRwX5jxU TeAxJDU3UCjD3ZAJAHcuqYm6aBs3SUn7W2UTVgwmh5WsdyBc6QpYZhHGaWFp6VY8Ksbg dynPW2Icaw+YebiIiw9ULfFkNWhrmpLd8Y0WMmqG6Txm32URH6wRs0DK2y+I2N0UVBny lHPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hHGVAWJwOOn2JPhMT1NM/vymvEBWtKs+uOwkwuwyItE=; b=UffG1sClSk82xap9YXUgquMJEVLf8eg5+iaOUnfkertBl8njnlvlIrMz/uC4N3KuLB JN8sDEwszGcNqZB+82rSaffl9Lh4x31Cn/5efMvZMeahvrCG8FEuuAQpXa6vfoabjezx 05z7T5N5KCjClSG3+44Iovq6fOa/WENIzhwlD6wYWY/wzMGRnpzHNQU2DRFdyCl/JXJP YPBnGCbe9prhhvAn5xb2NbJ6QyI351hinrrxx80qIj0aBMdINGCJBjiUCpAb66I9upTE ghJIU3J6qnGvRN611Jn1DdBmhlkwFZXDTRlThDHOrKzLSD7euirBJrth+jTClXtKuTJc ldvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cKOaG8Xg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a23si12400659plm.334.2018.12.11.08.17.19; Tue, 11 Dec 2018 08:17:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cKOaG8Xg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729148AbeLKQPn (ORCPT + 99 others); Tue, 11 Dec 2018 11:15:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:36874 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728813AbeLKPs3 (ORCPT ); Tue, 11 Dec 2018 10:48:29 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 58E5F20989; Tue, 11 Dec 2018 15:48:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543308; bh=TFCQVVpN6xbsIzEz8Sou9z1810iA0Asiud9LMxEMOO0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cKOaG8Xgc7F3JtZLS8wSKGz5XR4bphWlm9xWaYk8VRtZQsYeKnX8kDNlSnyoc141R ZEXvRxrCDz2FKDC04NymD0qg1GByVjCUDrxJV6WlTkPcheFdZezYhSNia6b6rGHOOx rvpU0pcIJodY5wbBQj0WhQRfgc8C99xtU85SNY+Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Geert Uytterhoeven , Robin Murphy , Joerg Roedel , Sasha Levin Subject: [PATCH 4.4 58/91] iommu/ipmmu-vmsa: Fix crash on early domain free Date: Tue, 11 Dec 2018 16:41:17 +0100 Message-Id: <20181211151610.773234116@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151606.026852373@linuxfoundation.org> References: <20181211151606.026852373@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit e5b78f2e349eef5d4fca5dc1cf5a3b4b2cc27abd ] If iommu_ops.add_device() fails, iommu_ops.domain_free() is still called, leading to a crash, as the domain was only partially initialized: ipmmu-vmsa e67b0000.mmu: Cannot accommodate DMA translation for IOMMU page tables sata_rcar ee300000.sata: Unable to initialize IPMMU context iommu: Failed to add device ee300000.sata to group 0: -22 Unable to handle kernel NULL pointer dereference at virtual address 0000000000000038 ... Call trace: ipmmu_domain_free+0x1c/0xa0 iommu_group_release+0x48/0x68 kobject_put+0x74/0xe8 kobject_del.part.0+0x3c/0x50 kobject_put+0x60/0xe8 iommu_group_get_for_dev+0xa8/0x1f0 ipmmu_add_device+0x1c/0x40 of_iommu_configure+0x118/0x190 Fix this by checking if the domain's context already exists, before trying to destroy it. Signed-off-by: Geert Uytterhoeven Reviewed-by: Robin Murphy Fixes: d25a2a16f0889 ('iommu: Add driver for Renesas VMSA-compatible IPMMU') Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/ipmmu-vmsa.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index 624e7ff76166..9101be1a6b59 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -372,6 +372,9 @@ static int ipmmu_domain_init_context(struct ipmmu_vmsa_domain *domain) static void ipmmu_domain_destroy_context(struct ipmmu_vmsa_domain *domain) { + if (!domain->mmu) + return; + /* * Disable the context. Flush the TLB as required when modifying the * context registers. -- 2.19.1