Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1065090ybl; Wed, 14 Aug 2019 10:08:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqx4h+NxDpERT624/4AfW8dC2lzr8j1kutB+PFlYz21SUCaObQygJt8ryOEcafuW26joz/mR X-Received: by 2002:a62:303:: with SMTP id 3mr996181pfd.118.1565802523916; Wed, 14 Aug 2019 10:08:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565802523; cv=none; d=google.com; s=arc-20160816; b=nKD+XWR3biPWG6Vx4TD9Mw5y15L9gX9dZAb28fihfLV9zXajuIBN1huuGezCF3AwEu GaHmA013rsXrbS5ox8Nketck2t1NmbgU03aCH0OyhxkNH87QRTS23rFU8Xo2FW6r3ia2 RkDhTrYLzGpVxb7XvQ/L2qK59pItDOnd39IP4GjzCr30iAkO/oRjb3JuFEcXOZXmxdzB vtyfdsoUgf4fyAtBqPHk0bNsf7QwnzylLxXfB8jdVguLB3L64S11w8gIbOftHbcEorvK mW9poROLyelBhZzGRbfVpeX44rnR5uSt9KvsBv1XKlqkT+DuimiSPs2lDX5tgLUBm5sf CT+w== 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=2X92JQyaz7k2o6No0t9FMjskjrtY8JQTfhggVuQT3ZQ=; b=DqOrr2D/1WnDxPfxf0EG3r7BQ7LSKirVP8P9PGbEaArUEBnrQk/aZ/97eNpMBzJqp1 KQP5UftdDUQMRE2unpdcqXM4YLiTm6i8TebHAw4kiDuY4HeO8iGHF+xZ7kuhYyPCL/QR xBRb6FAWpVZUo9ar0Ngt86pahIfufYjgzC+FoYo1BOjfPW43PRREORn5TUEyp8c9ziy6 vRQvWH1ilI51fZ4NeFarSwbVcQX7wtUv7HZFpzYlMcVJtScsx9MfkxpFOpAVZ/PeATY3 ubHN59m+r/hoCvP/xu0n/FvF3qJuUEX/mKuxsOk4+6dTcctuc3+mU5L+IiSGu/wSjusd iI3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Lnp9yVpX; 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 g9si206651pjv.37.2019.08.14.10.08.28; Wed, 14 Aug 2019 10:08:43 -0700 (PDT) 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=Lnp9yVpX; 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 S1729805AbfHNRHK (ORCPT + 99 others); Wed, 14 Aug 2019 13:07:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:56508 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729792AbfHNRHH (ORCPT ); Wed, 14 Aug 2019 13:07:07 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 5AA8A21721; Wed, 14 Aug 2019 17:07:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802426; bh=VtbA8zZWqby0Q8Drx6N71oFgtMUHUf+gQidEJvzWYpE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Lnp9yVpXPh5Cme8FyTmYMW8iprfxEZnpk+NcOKdraPHnrDynq2QL43vXrf5h6NSaH 2VPEjrDrUiAbM4Ol4F8ixBKIiZD7C9pIe79jAWEoKLAumkZyamvRjGimpzewmNW3Ow 17C8sTSU3rCPvz3gtDm/rwkPui7cXOMgqujJMRGo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Woodhouse , Joerg Roedel , Lu Baolu , iommu@lists.linux-foundation.org, Dmitry Safonov , Joerg Roedel , Sasha Levin Subject: [PATCH 5.2 085/144] iommu/vt-d: Check if domain->pgd was allocated Date: Wed, 14 Aug 2019 19:00:41 +0200 Message-Id: <20190814165803.429413517@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165759.466811854@linuxfoundation.org> References: <20190814165759.466811854@linuxfoundation.org> User-Agent: quilt/0.66 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 [ Upstream commit 3ee9eca760e7d0b68c55813243de66bbb499dc3b ] There is a couple of places where on domain_init() failure domain_exit() is called. While currently domain_init() can fail only if alloc_pgtable_page() has failed. Make domain_exit() check if domain->pgd present, before calling domain_unmap(), as it theoretically should crash on clearing pte entries in dma_pte_clear_level(). Cc: David Woodhouse Cc: Joerg Roedel Cc: Lu Baolu Cc: iommu@lists.linux-foundation.org Signed-off-by: Dmitry Safonov Reviewed-by: Lu Baolu Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/intel-iommu.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 2101601adf57d..1ad24367373f4 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -1900,7 +1900,6 @@ static int domain_init(struct dmar_domain *domain, struct intel_iommu *iommu, static void domain_exit(struct dmar_domain *domain) { - struct page *freelist; /* Remove associated devices and clear attached or cached domains */ rcu_read_lock(); @@ -1910,9 +1909,12 @@ static void domain_exit(struct dmar_domain *domain) /* destroy iovas */ put_iova_domain(&domain->iovad); - freelist = domain_unmap(domain, 0, DOMAIN_MAX_PFN(domain->gaw)); + if (domain->pgd) { + struct page *freelist; - dma_free_pagelist(freelist); + freelist = domain_unmap(domain, 0, DOMAIN_MAX_PFN(domain->gaw)); + dma_free_pagelist(freelist); + } free_domain_mem(domain); } -- 2.20.1