Received: by 10.213.65.68 with SMTP id h4csp677040imn; Fri, 6 Apr 2018 07:10:16 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/yLNqsALyIpir7QY7s2x3BFMHGlcyKbfPlDdLdxU8GbMPdKh3V3PI7/qW6tzg7llZDblh9 X-Received: by 10.98.223.149 with SMTP id d21mr20480206pfl.160.1523023816183; Fri, 06 Apr 2018 07:10:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523023816; cv=none; d=google.com; s=arc-20160816; b=YvQtLXk+Z6RgqhzwjiRcdVr5G/4Msc9I+NwkDb7vuw3iqofh9tmU6JpFDPTMPfaVTD NoGsgjQpsaFI0kQJdZ7X5w0WuFXeeigMPxlaw52bxS+/LG+PnwQmjLgfDdp9ZoRUj7st w6NjmiFgw6s+tjOmWZ7F0fq3a5/s180HwDQuAs+KVGjzbZnD5W5qZPOWYzLup5Ep4dvm iDx56eMxwLUbEGvYRXV9uDj2KVjfvaKXq/UeaMawVjdSo+cbi+4b3uW4fpzVmiO/QWJl wgptny0H0RWq/yw4ms6ijsxx6900HscnEsRp03fqud01AOZ/LA/QtDIjbaFS0BtBNpn7 s2XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=p7HPsa0thHQRwW/4cgud5jwfkBKlzjOLTc0lyeWJG4Y=; b=ouhWbf2owWBmH/GYv9Ya34K2G8L5ruyTq3si8DCm/ocIAT0PSnnGu3y/DRclM7eQRh /Tf+0sTJZEiVWSBDZAGOblMp1PMspUP+ny0oCvYVodqmPWsh0nIlf5DWRA7ythB+BMDB DF4q1c/fEIJQIdJUuuPxyTDrSRstCUzt9VNizm8NlgfjIbeUXIrTH30v/C+XoGPAE90s HPd8IvmrdorawJmdlSKN3ocMbgjaXtcn8e6PsvGZfznU8z1wBqV9/QLLM2fvMbeB/2td 92t3Xf4dXRo3vjGuwUZ0raQTV0anGlfNXJIwV2FXoh5HIMMWfTzQa1d17gB6sJ5Z0K7u WSFg== ARC-Authentication-Results: i=1; mx.google.com; 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 o1-v6si8025620plk.330.2018.04.06.07.10.02; Fri, 06 Apr 2018 07:10:16 -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; 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 S932780AbeDFNkr (ORCPT + 99 others); Fri, 6 Apr 2018 09:40:47 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:35982 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932571AbeDFNkp (ORCPT ); Fri, 6 Apr 2018 09:40:45 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 46877DF0; Fri, 6 Apr 2018 13:40:44 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Gerlach , Pavel Machek , Tony Lindgren Subject: [PATCH 4.15 01/72] ARM: OMAP: Fix SRAM W+X mapping Date: Fri, 6 Apr 2018 15:23:36 +0200 Message-Id: <20180406084349.546848637@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084349.367583460@linuxfoundation.org> References: <20180406084349.367583460@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tony Lindgren commit eb85a355c3afd9379f5953cfe2df73632d14c884 upstream. We are still using custom SRAM code for some SoCs and are not marking the PM code mapped to SRAM as read-only and executable after we're done. With CONFIG_DEBUG_WX=y, we will get "Found insecure W+X mapping at address" warning. Let's fix this issue the same way as commit 728bbe75c82f ("misc: sram: Introduce support code for protect-exec sram type") is doing for drivers/misc/sram-exec.c. On omap3, we need to restore SRAM when returning from off mode after idle, so init time configuration is not enough. And as we no longer have users for omap_sram_push_address() we can make it static while at it. Note that eventually we should be using sram-exec.c for all SoCs. Cc: stable@vger.kernel.org # v4.12+ Cc: Dave Gerlach Reported-by: Pavel Machek Signed-off-by: Tony Lindgren Signed-off-by: Greg Kroah-Hartman --- arch/arm/plat-omap/include/plat/sram.h | 11 ---------- arch/arm/plat-omap/sram.c | 36 ++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 11 deletions(-) --- a/arch/arm/plat-omap/include/plat/sram.h +++ b/arch/arm/plat-omap/include/plat/sram.h @@ -5,13 +5,4 @@ void omap_map_sram(unsigned long start, unsigned long skip, int cached); void omap_sram_reset(void); -extern void *omap_sram_push_address(unsigned long size); - -/* Macro to push a function to the internal SRAM, using the fncpy API */ -#define omap_sram_push(funcp, size) ({ \ - typeof(&(funcp)) _res = NULL; \ - void *_sram_address = omap_sram_push_address(size); \ - if (_sram_address) \ - _res = fncpy(_sram_address, &(funcp), size); \ - _res; \ -}) +extern void *omap_sram_push(void *funcp, unsigned long size); --- a/arch/arm/plat-omap/sram.c +++ b/arch/arm/plat-omap/sram.c @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -42,7 +43,7 @@ static void __iomem *omap_sram_ceil; * Note that fncpy requires the returned address to be aligned * to an 8-byte boundary. */ -void *omap_sram_push_address(unsigned long size) +static void *omap_sram_push_address(unsigned long size) { unsigned long available, new_ceil = (unsigned long)omap_sram_ceil; @@ -60,6 +61,30 @@ void *omap_sram_push_address(unsigned lo return (void *)omap_sram_ceil; } +void *omap_sram_push(void *funcp, unsigned long size) +{ + void *sram; + unsigned long base; + int pages; + void *dst = NULL; + + sram = omap_sram_push_address(size); + if (!sram) + return NULL; + + base = (unsigned long)sram & PAGE_MASK; + pages = PAGE_ALIGN(size) / PAGE_SIZE; + + set_memory_rw(base, pages); + + dst = fncpy(sram, funcp, size); + + set_memory_ro(base, pages); + set_memory_x(base, pages); + + return dst; +} + /* * The SRAM context is lost during off-idle and stack * needs to be reset. @@ -75,6 +100,9 @@ void omap_sram_reset(void) void __init omap_map_sram(unsigned long start, unsigned long size, unsigned long skip, int cached) { + unsigned long base; + int pages; + if (size == 0) return; @@ -95,4 +123,10 @@ void __init omap_map_sram(unsigned long */ memset_io(omap_sram_base + omap_sram_skip, 0, omap_sram_size - omap_sram_skip); + + base = (unsigned long)omap_sram_base; + pages = PAGE_ALIGN(omap_sram_size) / PAGE_SIZE; + + set_memory_ro(base, pages); + set_memory_x(base, pages); }