From patchwork Thu Mar 16 13:36:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jon Medhurst (Tixy)" X-Patchwork-Id: 9628209 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 B642E6048C for ; Thu, 16 Mar 2017 13:36:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A694D285EB for ; Thu, 16 Mar 2017 13:36:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 997CB2864B; Thu, 16 Mar 2017 13:36:37 +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 4A387285EB for ; Thu, 16 Mar 2017 13:36:37 +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: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:In-Reply-To: References:List-Owner; bh=KCyeW5bk7cODkYaWQeNqwYZccA8Lnk5bJmHsqsFjM/w=; b=WFz r4I52pPEXOqY/bxYBksTIfXANJstcMp7m5ekCTq+onKCs29L/LzWH3oniFY43CXP/UKknWcO8bkHr PuT4nCqhEAkpUkTDwkHduXgjdspNgRaaPVHx1IqtUPfthdy/mOThqLJWBLYrjUp/2xdHjU3QzuBJ5 FhhXPEi9zXHZZ+jjkVOejJNLlOWB1fT04ZiT5uwrgLVQqJp4DXkyRXObSRN7F9Cti+77h9klcjs0X QCJD8ZExFo7h5nw4TsFmJh17SyVfnYEgMCwBy9wB6aqJEd2Pf6ORmAxRIS1UuIOXitsJa9Ocosx9/ eK7U0jWYfm30fviA3kIWcVvN0qssSOA==; 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 1coVa0-0004RN-SH; Thu, 16 Mar 2017 13:36:36 +0000 Received: from smarthost03c.mail.zen.net.uk ([212.23.1.22]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1coVZx-0004QL-Dz for linux-arm-kernel@lists.infradead.org; Thu, 16 Mar 2017 13:36:35 +0000 Received: from [82.69.122.217] (helo=plug1) by smarthost03c.mail.zen.net.uk with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1coVZa-0000Fu-Al; Thu, 16 Mar 2017 13:36:10 +0000 Received: from linaro1 ([192.168.2.110] helo=linaro2.home) by plug1 with esmtp (Exim 4.80) (envelope-from ) id 1coVZZ-0000yP-3o; Thu, 16 Mar 2017 13:36:09 +0000 Received: from tixy by linaro2.home with local (Exim 4.88) (envelope-from ) id 1coVZZ-0005uW-1U; Thu, 16 Mar 2017 13:36:09 +0000 From: Jon Medhurst To: Russell King Subject: [PATCH] arm: Fix text patching via fixmap with virtually tagged D-caches Date: Thu, 16 Mar 2017 13:36:09 +0000 Message-Id: <20170316133609.22679-1-tixy@linaro.org> X-Mailer: git-send-email 2.11.0 X-Originating-smarthost03c-IP: [82.69.122.217] Feedback-ID: 82.69.122.217 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170316_063633_635576_771C5399 X-CRM114-Status: GOOD ( 11.04 ) 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: Rabin Vincent , Kees Cook , linux-arm-kernel@lists.infradead.org, Nicolas Pitre 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 __patch_text_real changes an instruction via a fixmap on systems with a virtually tagged cache, there may still be a stale entry in the data cache for the real instruction address. Fix this by also flushing the cache at that address. One consequence of this issue is that if a kprobe is added then removed, the D-cache may still hold the breakpoint instruction from when the probe was active. In that situation, when re-inserting the kprobe, the kernel thinks the instruction being probed is a breakpoint instruction and will reject the attempt. This shows up with test failures when enabling CONFIG_ARM_KPROBES_TEST on a device with a Marvel Kirkwood SoC and also enabling CONFIG_STRICT_KERNEL_RWX which triggers the use of fixmaps. Fixes: ab0615e2d6fb ("arm: use fixmap for text patching when text is RO") Signed-off-by: Jon Medhurst --- arch/arm/kernel/patch.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c index 020560b2dcb7..c3c64bc2f50d 100644 --- a/arch/arm/kernel/patch.c +++ b/arch/arm/kernel/patch.c @@ -101,6 +101,7 @@ void __kprobes __patch_text_real(void *addr, unsigned int insn, bool remap) if (waddr != addr) { flush_kernel_vmap_range(waddr, twopage ? size / 2 : size); patch_unmap(FIX_TEXT_POKE0, &flags); + flush_kernel_vmap_range(addr, size); } else __release(&patch_lock);