From patchwork Wed Apr 5 19:21:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Gerlach X-Patchwork-Id: 9665531 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 A323A60352 for ; Wed, 5 Apr 2017 19:22:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8EB2026530 for ; Wed, 5 Apr 2017 19:22:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82ADB26E94; Wed, 5 Apr 2017 19:22: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_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 4B34726530 for ; Wed, 5 Apr 2017 19:22:23 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=pZjqrRD6oTqOS8NdE5bBdlGopr8agoDpKBKsgc2FTio=; b=XOnXdeIh2Apque Xi+4dJH9YSRfMhJ7ASWkKh57+aWn/vvhNOeU/9hGq589DPb07N92XFjT4oYG7uGDGrgnpbs2rXvND 5MKOdUIQz+0qpk4DWH0VXPBGiSctko6brJ1ZM23Rk8xdMvKdDaQhDHw8ql5dgdjbtqEPtdimHFlmr ekf9n/lGIyN9vmOjxz8kIg5uiFmXgXkXlDfJCAjq1FrNIX926CFYbSwgCyuNuX66KH2dvrhsAiTat m+pVpazi78OG7tyKE4S8P+VeTX3zryS+8nQGqG8cOpiUfk+vCGCWbv8wNGmwdNfY6id1uJmMFWxxg 0USM5tDGg7z1niQF7MOw==; 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 1cvqVX-0007nF-Sj; Wed, 05 Apr 2017 19:22:19 +0000 Received: from lelnx194.ext.ti.com ([198.47.27.80]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cvqVU-0007kU-Ck for linux-arm-kernel@lists.infradead.org; Wed, 05 Apr 2017 19:22:18 +0000 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by lelnx194.ext.ti.com (8.15.1/8.15.1) with ESMTP id v35JLZKo021544; Wed, 5 Apr 2017 14:21:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1491420095; bh=Jmcqy7U2ZIe+1bdIR8gR+CUxBMMu66HSI47y3XXtdu8=; h=From:To:CC:Subject:Date; b=RSYSV8+3becyas3DnQNlEY8IpANl2RfoUq0McV/wowNZoOOmUa7RpYHG4bgktBh09 JQNMtRxMtplxNr5XyvEYyMwyvOwAGXU4n1a4dwsjc8Y4Lu9bTAB2huDsQ9Pp+6lzP/ ICEb9bmgMfV8+lTDmE7WWjnHx3eXXp2IisJNWTds= Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id v35JLYaN012488; Wed, 5 Apr 2017 14:21:34 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.3.294.0; Wed, 5 Apr 2017 14:21:33 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id v35JLYhK017284; Wed, 5 Apr 2017 14:21:34 -0500 Received: from localhost (uda0274052.am.dhcp.ti.com [128.247.83.19]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id v35JLY329752; Wed, 5 Apr 2017 14:21:34 -0500 (CDT) From: Dave Gerlach To: Greg Kroah-Hartman , Arnd Bergmann , Tony Lindgren , Russell King Subject: [PATCH] misc: sram-exec: Use aligned fncpy instead of memcpy Date: Wed, 5 Apr 2017 14:21:20 -0500 Message-ID: <20170405192120.1009-1-d-gerlach@ti.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170405_122216_552754_57A8F968 X-CRM114-Status: GOOD ( 10.08 ) 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: Dave Gerlach , Keerthy J , linux-kernel@vger.kernel.org, Alexandre Belloni , linux-omap@vger.kernel.org, Shawn Guo , linux-arm-kernel@lists.infradead.org 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 Currently the sram-exec functionality, which allows allocation of executable memory and provides an API to move code to it, is only selected in configs for the ARM architecture. Based on commit 5756e9dd0de6 ("ARM: 6640/1: Thumb-2: Symbol manipulation macros for function body copying") simply copying a C function pointer address using memcpy without consideration of alignment and Thumb is unsafe on ARM platforms. The aforementioned patch introduces the fncpy macro which is a safe way to copy executable code on ARM platforms, so let's make use of that here rather than the unsafe plain memcpy that was previously used by sram_exec_copy. In the future, architectures hoping to make use of the sram-exec functionality must define an fncpy macro just as ARM has done to guarantee or check for safe copying to executable memory before allowing the arch to select CONFIG_SRAM_EXEC. Signed-off-by: Dave Gerlach --- drivers/misc/sram-exec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/misc/sram-exec.c b/drivers/misc/sram-exec.c index ac522417c462..0057eabe5c03 100644 --- a/drivers/misc/sram-exec.c +++ b/drivers/misc/sram-exec.c @@ -19,6 +19,7 @@ #include #include +#include #include "sram.h" @@ -93,7 +94,7 @@ int sram_exec_copy(struct gen_pool *pool, void *dst, void *src, set_memory_nx((unsigned long)base, pages); set_memory_rw((unsigned long)base, pages); - memcpy(dst, src, size); + fncpy(dst, src, size); set_memory_ro((unsigned long)base, pages); set_memory_x((unsigned long)base, pages);