Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp797693imu; Tue, 11 Dec 2018 07:45:20 -0800 (PST) X-Google-Smtp-Source: AFSGD/Ul2HK4wSI1GfWmaJ7tast4nJNY8Gl/yHy118atLroDl0qEa3643agSG3leNCTMOyiHcekY X-Received: by 2002:a17:902:b494:: with SMTP id y20mr16817260plr.178.1544543120334; Tue, 11 Dec 2018 07:45:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544543120; cv=none; d=google.com; s=arc-20160816; b=tRDQmOU1oeoRr3O6kG76kaS3yiQvz3Tk9rZdT0e3S56YQYyr6ZjK+Uok51EGLZ9Den xjwirjNRD2NNwd865Ce8lK7hzViaJCoPakWvh6sd70fcxThgaZEtesqKMMA5zKuZH5XB ByxOD266r2pIv9y2iWVeD44I+x9sAdGqombPpw6w4+s0Xrt2FRnqKj9r4eFQapFTE6HO SfbSfrhccmiSWFTfJCtxk3zIPS1kiI5C0pT1XiwdWr33puobt2huoe0f9uIoxkZq9dbI JdwTytDVB3OzHCrKaNoe0MtVnI04SovHkNe47EmfVprmWHjQk4JvNEIMDOpUYoC+KbqO NZyw== 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=PtinT2gGwy72ZwLxpNRq1fodVhLs9K/dSZH7znIe6W0=; b=tkN5iTrsulC2WVQ4s5JqjgK8tMQ8Bm3Q39SHaOZwtAV05PSPI8Jr486vz13EFIqc8P pbLJBNtvE+sSczAI2itDE7sLJtRj+FnlNFFln3hpVWq10LYx6w+Z56y81AUyCVKFOOf4 iOegnXb+xdgJf0+14dkl1Et4fbcbl+SU/cCAZnGZKQz/zkPnn8x2A1WlNG07n3XI9wEv fhorC8yBkOHJ9Iwz42mVhyhO9GxvM2j9vbvQg6Rp+3jQxBdr2YCNiKm1BkoSlSsZtou4 euEFw21429qA4tGhctRYOVpcIklBX4BoskpSVSDg40lUKI+hpZhXQSXtV1RSd9SiAGrx EYAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nX5TRA8p; 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 l66si13541124pfi.5.2018.12.11.07.45.03; Tue, 11 Dec 2018 07:45: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=nX5TRA8p; 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 S1727601AbeLKPnl (ORCPT + 99 others); Tue, 11 Dec 2018 10:43:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:60136 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727230AbeLKPng (ORCPT ); Tue, 11 Dec 2018 10:43:36 -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 CB33220672; Tue, 11 Dec 2018 15:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543015; bh=PFUHQ0lZ7W+tzOoOz1jobs+RqyC9CUusRAhw8OJpDdg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nX5TRA8p6i2aI2X8CizJ/iAV5WvXFkWSwyfOfIwAQBF1yIonZ3E5gpGK1FNZ0pJQL eY6Jo98x9w7oruC3JdJooHQik50B0MNXYFURWST+nvBhPyg3P0A5YIaZilD7hebHBA YdB5V1U366uglzs8+vczsidg3DyZK+QPr+SSihDU= 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 3.18 34/54] iommu/ipmmu-vmsa: Fix crash on early domain free Date: Tue, 11 Dec 2018 16:41:22 +0100 Message-Id: <20181211151548.012124488@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151546.010073210@linuxfoundation.org> References: <20181211151546.010073210@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 3.18-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 7dab5cbcc775..47e8db51288b 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -383,6 +383,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