Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2082419imu; Wed, 28 Nov 2018 22:04:20 -0800 (PST) X-Google-Smtp-Source: AFSGD/VrUP8hXyBKHl39PXnh+iOcDklWfjKL9Xr2HY2TfbBd8kyyuI2kNz8zwMrBSp4vGkZwbtMk X-Received: by 2002:a63:5207:: with SMTP id g7mr158785pgb.253.1543471460758; Wed, 28 Nov 2018 22:04:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543471460; cv=none; d=google.com; s=arc-20160816; b=Yb1XNNCZ9yDcWpQK/CJm2rCiay4f8Lv+I/Zxky/cv2HyDzIyxtJqehzrOSfSROObgP Js1zBbsvi88zeN0QiVrs54e9NvjyJxxZJgXtVLODZTePbWa8BnO7nUNeAVgEg993Pzxx Xk2cVa7iBkiRpcJoGOGJ9+vQAv50h7UkmXLRtYSQh1hNau+CB+xQ8Blt0JyUXJpPv0zF wb4f/jw7oUl0Ef8XTCBeA1RBTvsAao4hEI+BFBH5uXPYsSzRQts10eqxObd+gExi7LvN V4eKrSgVI3NduQbe0iTpY7tlkmQN3yeg6pyymGA3fgzIfnNgBIbkzSQ348PnzJstRF2T D0Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=D2nz0KDS8v2dQubvxVz/CxQTuQs78urz7PsTj7q0qw8=; b=Az9uq50xf3zOzhDQ46CDpM7jwnWJNWUZ/0MfThZnS2PrgFRGy1510Vt6YP+5aLT6Ai I2eBWwa8GT/kcdPY/eBOXjE6tAlyehv2KW2jqoAvW06649JQgsWGiM0ftVC9MnBSsSpw 8tfWs7QKwct3FBVuTKQqwxBdsyTjxmSnf5rS7zCbJK/y6ol3sB/uoXPU96pH8unlWNtm H3GZfo+XcVIvq2IrQ6ewTqgV+JOlh9eMvFkmIm3Fc9hr9zGHQ3ZkrHITDpcJZTcQeIcz nzSH+PiPW7z1bteL9zyvJ3uhPcSnhbXlb/BH7teFnQFRknnYQHJrxu8j5KjfJUSuxH9h BUZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xB4jIYkA; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x74si1235136pfe.23.2018.11.28.22.04.06; Wed, 28 Nov 2018 22:04:20 -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=xB4jIYkA; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729383AbeK2RFm (ORCPT + 99 others); Thu, 29 Nov 2018 12:05:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:41088 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727767AbeK2RFl (ORCPT ); Thu, 29 Nov 2018 12:05:41 -0500 Received: from sasha-vm.mshome.net (unknown [37.142.5.207]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A7D3F208E7; Thu, 29 Nov 2018 06:01:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543471290; bh=IqblzcFp1cbycVKLUyiEi8+VdLM7v9cLGhtcC9c7xR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xB4jIYkArZIEd29p48rxijXsQ6PhIr8rKQn3xJcnGhLz5vWDyT2fho43l6PCTVwgv hK7Ty2IAjbn/C7MFD8XxNJ5JkjgV7+4l1LmNpILFoJ+YgtsURuyzcqt9fNsmhBLk+u noskaEBk/GTFEsVmsH0uOxumtjSqRfFw9nvVjuA0= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Geert Uytterhoeven , Joerg Roedel , Sasha Levin , iommu@lists.linux-foundation.org Subject: [PATCH AUTOSEL 4.14 04/35] iommu/ipmmu-vmsa: Fix crash on early domain free Date: Thu, 29 Nov 2018 01:00:38 -0500 Message-Id: <20181129060110.159878-4-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181129060110.159878-1-sashal@kernel.org> References: <20181129060110.159878-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Geert Uytterhoeven [ 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 5d0ba5f644c4..777aff1f549f 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -424,6 +424,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.17.1