Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp830175imu; Tue, 11 Dec 2018 08:12:51 -0800 (PST) X-Google-Smtp-Source: AFSGD/VPuPs02lyvhG7h6C35OYopluGA3P+teP6mqy7LFMTWZIAGZSiqfjw1aFbq3IMJUzcey+Bj X-Received: by 2002:a62:4255:: with SMTP id p82mr16678788pfa.13.1544544771178; Tue, 11 Dec 2018 08:12:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544544771; cv=none; d=google.com; s=arc-20160816; b=F+PzF3CBM1aDzLUN0zBUpo1F1ek8XMMHfYx4j7L1XgsAQJjzdeNEf13ZomEe9KRKpJ MwCY7YIqTdQdUmSuRhgmR07qSDKIDKl6K2laRd02aq3Q9xCeRr5exYp+TtvZ2JOG8DlP oljSH9x8BUO1Wto0wBsDis42aw/YJMCd1/TpBmnyzw1iWjDWlmC/32uVknsRODqN/0hz zb+VU1cy6BQK/4WXjRo5rDqRFeXBqiVStm+8ubKyfgG91OCCFmOAPS01xRDZ/bLI3wYl iexi4b287QKg2eZgvYdjXlD2IJT/wN5HrkNukcCVpOfwEdVxSpGUdBH3KrGxRIJvND6f mkIQ== 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=nrfneCFDFRbnLu/0xZxcqeVG42scyKSK6nlBM5r0sHM=; b=lMpvZLg2KBMZpkXWRhGHtK/HrFDGoguFhu2DJJ39R0VFNn7yhSIkwxUnWLycxUYfy2 hSlzvJGDTETT85+pmF8ijrzfskJb+3DglmIsjWHtI0paFA2W06qYTGcBDKBIXouWoitS XmmtoyFwbo2kpZDtRSTXsIAnVyKyInYKr8JWv+3DxndYBMvQn9RM/D1EWoVpA+zJUns6 BX66t2DWhohzJwZQKFNkwwMObjt3aSDC2c3pQPQOqgLe2AfwfEpu4MI3tcc3Hmua8a9s LKcJOrnXuYDGA2NowRQnST1OlaH3pULXpcn18QpwjSZWFtp6uaL9MDL1fqMKaPCW/5Ys wIag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VFzjU3DV; 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 o32si11899378pld.407.2018.12.11.08.12.36; Tue, 11 Dec 2018 08:12:51 -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=VFzjU3DV; 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 S1730085AbeLKQJa (ORCPT + 99 others); Tue, 11 Dec 2018 11:09:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:41048 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729678AbeLKPwW (ORCPT ); Tue, 11 Dec 2018 10:52:22 -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 F104820855; Tue, 11 Dec 2018 15:52:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543541; bh=9GpkMUc592Vnk4Sgj9ziB7SSs/BHql6+9blfeMSh3lk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VFzjU3DVn7Q1MAwMhUewZrwP5VsiaIRjq4HR8dMR7p2iHLMeTh0zIRuhl9x8sMydS KssshktCplqi7LZ9xoJGxef1Ifts/6d4RAayfKAJ5PPsqKv/2+Rn9TiWQ1CsE2JshI WkAJU+jBSRI61YAlogcZWNT8Bc3UgdBJH5ojnHuU= 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.14 04/67] iommu/ipmmu-vmsa: Fix crash on early domain free Date: Tue, 11 Dec 2018 16:41:04 +0100 Message-Id: <20181211151630.590896600@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151630.378216233@linuxfoundation.org> References: <20181211151630.378216233@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.14-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 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.19.1