From patchwork Mon Feb 27 12:30:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 9593069 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B9DF860453 for ; Mon, 27 Feb 2017 12:32:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEF192811E for ; Mon, 27 Feb 2017 12:32:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3A9D28178; Mon, 27 Feb 2017 12:32:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 68C662811E for ; Mon, 27 Feb 2017 12:32:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=I+gNdBS7LItAa9av55/AZDIkRp1t4f0TK7LGcnPe0Ws=; b=GY/FSlEVIOOHW9XYUXhV7pyEC4 bxshNlCaOs0asI9VEweVccnksX2eBiYnIOTY8gmnWe/0pVdGFYPeH22ZhHYH16K/+NGH/pc82Cgvx DP/8mb1wKi4Qhy8SfLLbLWUaowluMpgzcc0HX8qFbvu/toD1RE3DUPtTtH0ptW32vZ1hin6Ms1B4d Lj7A2jXqdSJeOTGGqzVnP7i8WraYWiGf233rPNI6nX/hSpkAU/8/psX8nGbN+NG9V0Rv1XUhfIATZ pUyqhFS/2dY3BHA9M7cfMe+X2SoPKGLfp8PsR17d7m/rRm+XC/cQUoYjiFt+ZqFPzdd1hT8pH+YaC PFyHKD8g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ciKTX-0003gU-TT; Mon, 27 Feb 2017 12:32:23 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ciKSK-00035F-W9 for linux-arm-kernel@lists.infradead.org; Mon, 27 Feb 2017 12:31:12 +0000 Received: by mail-wm0-x241.google.com with SMTP id m70so13193991wma.1 for ; Mon, 27 Feb 2017 04:30:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BazvZXaBbEuWDyw5ZOIp425TQ39waPO+W8lqqDy4x+Q=; b=N8j0KO0KTXhCb8/dES24sldJlZFW6razJ98VjvS6Sn8g9YbC2e6bjN3JpXwxryzI1o T65KbDAb8sfpx7D1t2P7kl87XMdgUp8A2rkKOVP7VdbPP7jYst5DX+PH+Yh/4lMZKU8B s331Ug/e47rbbEaIzwIc8NlY72V6+4LYbFINWgpGm7NOn4fMLKwVuuNkcdyIgLSB+0p3 1ERQEVH7+VZ+rlYQqAiOeXBVnzJ8PlFgnQBI8/xm+Ku4JNOSChOPeNWn54kUC4puFlcN yRQ5IPTDCoeqdhKUFVQM4qp+Rw11UlA+qcg8zB+dHcXNGm7L6SPdL8TdC3/udd+nSBZV X5qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BazvZXaBbEuWDyw5ZOIp425TQ39waPO+W8lqqDy4x+Q=; b=UnWezId8hZcmWyNpAYZVgrjZdIsj6KWcasU9J2UluBOqfE5YqO1rvoRLqvIPZCl1eF fa3J9fV7vMM45K0GJpzOlvv+ChAZ/eQIfruekrBo9JlDJlTlAC5CT08MD2UYJwqwDz+i Nl2AggrpIUuSVz6mYc1ruyk3Jlt3jMzytccsdxuE2q6FiwsvrwCIBnr0ZfdOgJ9IJzLA RpIMC4m3dRBZV3Mrk8hinLtIgwOcSHnLk3LyvVZIjpy6icvgj28kWIMMbmqGIjw8DueT dZKOuJVxSyZIVuuK7rkYisnxwSbsenvJfHUxNVtnyBvuDgck0182Xl6ZVYvZuBiE72IB UdCQ== X-Gm-Message-State: AMke39lFGaGsS+nES1ZHLefoMcJtUmeRewnLTmprDtEirCZQjlYUf3UE0XbJM6tiOwTlDA== X-Received: by 10.28.104.6 with SMTP id d6mr5544020wmc.79.1488198647328; Mon, 27 Feb 2017 04:30:47 -0800 (PST) Received: from otyshchenko.kyiv.epam.com (ll-74.141.223.85.sovam.net.ua. [85.223.141.74]) by smtp.gmail.com with ESMTPSA id u198sm14076008wmf.9.2017.02.27.04.30.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Feb 2017 04:30:46 -0800 (PST) From: Oleksandr Tyshchenko To: linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org Subject: [PATCH v1 2/2] iommu/io-pgtable-arm-v7s: Check for leaf entry before dereferencing it Date: Mon, 27 Feb 2017 14:30:26 +0200 Message-Id: <1488198626-1884-3-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488198626-1884-1-git-send-email-olekstysh@gmail.com> References: <1488198626-1884-1-git-send-email-olekstysh@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170227_043109_188986_CEE160EB X-CRM114-Status: GOOD ( 10.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vlad.babchuk@gmail.com, joro@8bytes.org, will.deacon@arm.com, andrii.anisov@gmail.com, andr2000@gmail.com, al1img@gmail.com, robin.murphy@arm.com, joculator@gmail.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Oleksandr Tyshchenko Do a check for already installed leaf entry at the current level before dereferencing it in order to avoid walking the page table down with wrong pointer to the next level. Signed-off-by: Oleksandr Tyshchenko CC: Will Deacon CC: Robin Murphy --- drivers/iommu/io-pgtable-arm-v7s.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c index 1c049e2..8d6ca28 100644 --- a/drivers/iommu/io-pgtable-arm-v7s.c +++ b/drivers/iommu/io-pgtable-arm-v7s.c @@ -422,8 +422,12 @@ static int __arm_v7s_map(struct arm_v7s_io_pgtable *data, unsigned long iova, pte |= ARM_V7S_ATTR_NS_TABLE; __arm_v7s_set_pte(ptep, pte, 1, cfg); - } else { + } else if (ARM_V7S_PTE_IS_TABLE(pte, lvl)) { cptep = iopte_deref(pte, lvl); + } else { + /* We require an unmap first */ + WARN_ON(!selftest_running); + return -EEXIST; } /* Rinse, repeat */