From patchwork Wed May 3 15:37:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristina Martsenko X-Patchwork-Id: 9710037 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 BA92660351 for ; Wed, 3 May 2017 15:58:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A96D528662 for ; Wed, 3 May 2017 15:58:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E55228667; Wed, 3 May 2017 15:58:29 +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_SIGNED, DKIM_VALID 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 4C18728662 for ; Wed, 3 May 2017 15:58:29 +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=a7IkkgJGNi87ZAtWgO5e0Q9rP0qdp9ZKiQMbbqdiGnQ=; b=uYvptua5wEvFyGo4HvZguK9+GH stLBZ47d/xrk8W9me//x+3nNGdCBW3U19SdsCtu3gcSCWuh0AUgYZcADkRz7TTiusjE0/kr1Qaht4 vQhmFUZHnmtjt1CmX86i8Jd6IUtfxpojM+dVPBCpj2wwndCwhJkiZih/dc9zrl9UR2OIZjcZ7iPtn WOC5OH/ZFRbG8rEWEtrAtv5uZflBjlJRxIy1XSRq0dnKcZrzhcHgczZ6Ha8+ADqv/PDm6kXDcIyLO o7TAQ9rQWWp66LZ4CX62WcQB78XOOZwg1ZZIln9JtPmD2VhqRySvEQappdK+6AOn3+YXSNLpWYfhj 4Z93TylA==; 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 1d5wfc-0004iT-57; Wed, 03 May 2017 15:58:28 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d5wfW-0004UN-W3 for linux-arm-kernel@bombadil.infradead.org; Wed, 03 May 2017 15:58:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=zbwcO9yh6oY8EY6mwNAZoV8Mi56XAHVXpYAExNbhGJE=; b=3Vn+RgXA3ctgFY8MkC5lMcSMe wxNfvwJ89VXkZ8PgYFtqb1ysTLL8dCg/QgPcnt5xv6+NMWukv4L5b9ZvNqRr4Ec+o7WZ9u8O8KUZJ fkYYKWjbQbCsPk37jS0HEtu9W+yjLudgobHI/GcpJC7ru8bQ9Qtt3bkIXkps7YImi3sgIpCN4awPp X6UMSSKbD23C+xwbkcxA9KmzjoPczSBifcZ0gsLiZCD+0NiAgIQ8PtmTh1knRAP1DNt3erTbYSGew Ww2xysfz6tN3VdFiIv0vPcSeMoDB94Wd2+NWu0jdRImx8bil1PmisPNEMOmZR0FOrgs0Vw5iS+PlK 2GEFLuY/Q==; Received: from foss.arm.com ([217.140.101.70]) by merlin.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d5wMz-0005jk-Lx for linux-arm-kernel@lists.infradead.org; Wed, 03 May 2017 15:39:15 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BB84B80D; Wed, 3 May 2017 08:38:22 -0700 (PDT) Received: from moonbear.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 95D773F3E1; Wed, 3 May 2017 08:38:21 -0700 (PDT) From: Kristina Martsenko To: Will Deacon , Catalin Marinas Subject: [PATCH v2 1/4] arm64: traps: fix userspace cache maintenance emulation on a tagged pointer Date: Wed, 3 May 2017 16:37:45 +0100 Message-Id: <1493825868-30872-2-git-send-email-kristina.martsenko@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1493825868-30872-1-git-send-email-kristina.martsenko@arm.com> References: <1493825868-30872-1-git-send-email-kristina.martsenko@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170503_113913_845607_56C17F2C X-CRM114-Status: GOOD ( 16.95 ) 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: Mark Rutland , Andre Przywara , Dave Martin , linux-arm-kernel@lists.infradead.org, Marc Zyngier 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 When we emulate userspace cache maintenance in the kernel, we can currently send the task a SIGSEGV even though the maintenance was done on a valid address. This happens if the address has a non-zero address tag, and happens to not be mapped in. When we get the address from a user register, we don't currently remove the address tag before performing cache maintenance on it. If the maintenance faults, we end up in either __do_page_fault, where find_vma can't find the VMA if the address has a tag, or in do_translation_fault, where the tagged address will appear to be above TASK_SIZE. In both cases, the address is not mapped in, and the task is sent a SIGSEGV. This patch removes the tag from the address before using it. With this patch, the fault is handled correctly, the address gets mapped in, and the cache maintenance succeeds. As a second bug, if cache maintenance (correctly) fails on an invalid tagged address, the address gets passed into arm64_notify_segfault, where find_vma fails to find the VMA due to the tag, and the wrong si_code may be sent as part of the siginfo_t of the segfault. With this patch, the correct si_code is sent. Fixes: 7dd01aef0557 ("arm64: trap userspace "dc cvau" cache operation on errata-affected core") Signed-off-by: Kristina Martsenko --- Note that patch #3 would also fix the first bug (incorrect segfault), but not the second (wrong si_code), hence this patch. arch/arm64/kernel/traps.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index e52be6aa44ee..45c8eca951bc 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -443,7 +443,7 @@ int cpu_enable_cache_maint_trap(void *__unused) } #define __user_cache_maint(insn, address, res) \ - if (untagged_addr(address) >= user_addr_max()) { \ + if (address >= user_addr_max()) { \ res = -EFAULT; \ } else { \ uaccess_ttbr0_enable(); \ @@ -469,7 +469,7 @@ static void user_cache_maint_handler(unsigned int esr, struct pt_regs *regs) int crm = (esr & ESR_ELx_SYS64_ISS_CRM_MASK) >> ESR_ELx_SYS64_ISS_CRM_SHIFT; int ret = 0; - address = pt_regs_read_reg(regs, rt); + address = untagged_addr(pt_regs_read_reg(regs, rt)); switch (crm) { case ESR_ELx_SYS64_ISS_CRM_DC_CVAU: /* DC CVAU, gets promoted */