From patchwork Fri Apr 4 19:58:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rabin Vincent X-Patchwork-Id: 3940841 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 27A3FBFF02 for ; Fri, 4 Apr 2014 20:25:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3F1F820395 for ; Fri, 4 Apr 2014 20:25:20 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 39E9920383 for ; Fri, 4 Apr 2014 20:25:19 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WWAGw-0000yH-40; Fri, 04 Apr 2014 19:59:32 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WWAGL-0006Q6-KD; Fri, 04 Apr 2014 19:58:53 +0000 Received: from mail-la0-x233.google.com ([2a00:1450:4010:c03::233]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WWAGG-0006NS-Al for linux-arm-kernel@lists.infradead.org; Fri, 04 Apr 2014 19:58:51 +0000 Received: by mail-la0-f51.google.com with SMTP id pv20so2910728lab.10 for ; Fri, 04 Apr 2014 12:58:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=fK2H2XrbvyV7lvbUNFC9fx6d7MFlBQqe7fqXVzdlkPo=; b=EJf7UkDyh+jmnV2MEO39cWFfRItPElj/Z1WcTDPku3YSd/JMndgnYgidzDKp0tl+Ub 4Z1WxFqpsLvPOsEzUKCRhTj1HXLcTbbooeV+c6/C/gpnBOoHt8sJ8xBvMEj4GNZzip9U BR9i1bAI6x0r1ZhY2jNgao/uSYV8tcphOH4Ho0fACkE/i/AQ/J2pIB7+E8a+SRAzBlKH UCajgLBoKUOYTosDcJLHJ+LYVS+qcTuAhD61t6S1X1z3zk11HLh6S3GN4bH/0kV/W3lz D6cmBc1+zH2Oi8mwKIxL/Kt+U7ExYV0z0BOXTGC9X9NPqJoOiRJ6vHbbbOf9XlX5npod YLIQ== X-Received: by 10.152.26.66 with SMTP id j2mr10064269lag.25.1396641503656; Fri, 04 Apr 2014 12:58:23 -0700 (PDT) Received: from debian (217-211-190-200-no39.tbcn.telia.com. [217.211.190.200]) by mx.google.com with ESMTPSA id qf1sm6289201lbc.8.2014.04.04.12.58.22 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 04 Apr 2014 12:58:23 -0700 (PDT) Date: Fri, 4 Apr 2014 21:58:18 +0200 From: Rabin Vincent To: Kees Cook Subject: Re: [PATCH 2/2] ARM: mm: make text and rodata read-only Message-ID: <20140404195818.GA21028@debian> References: <1396577719-14786-1-git-send-email-keescook@chromium.org> <1396577719-14786-3-git-send-email-keescook@chromium.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1396577719-14786-3-git-send-email-keescook@chromium.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140404_155848_522956_8F9F68A7 X-CRM114-Status: GOOD ( 16.81 ) X-Spam-Score: -1.9 (-) Cc: Russell King , Catalin Marinas , Will Deacon , linux-kernel@vger.kernel.org, Laura Abbott , Alexander Holler , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Apr 03, 2014 at 07:15:19PM -0700, Kees Cook wrote: > diff --git a/arch/arm/kernel/ftrace.c b/arch/arm/kernel/ftrace.c > index 34e56647dcee..4ae343c1e2a3 100644 > --- a/arch/arm/kernel/ftrace.c > +++ b/arch/arm/kernel/ftrace.c > @@ -14,6 +14,7 @@ > > #include > #include > +#include > > #include > #include > @@ -34,6 +35,22 @@ > > #define OLD_NOP 0xe1a00000 /* mov r0, r0 */ > > +static int __ftrace_modify_code(void *data) This is in the CONFIG_OLD_MCOUNT ifdef, but should be in the outer ifdef (CONFIG_DYNAMIC_FTRACE) instead, otherwise it will not get enabled for for example Thumb-2 kernels. This was wrong in my example patch too. > diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c > index 8539eb2a01ad..3baac4ad165f 100644 > --- a/arch/arm/mm/init.c > +++ b/arch/arm/mm/init.c > @@ -681,30 +716,52 @@ static inline bool arch_has_strict_perms(void) > return true; > } > > +#define set_section_perms(perms, field) { \ > + size_t i; \ > + unsigned long addr; \ > + \ > + if (!arch_has_strict_perms()) \ > + return; \ > + \ > + for (i = 0; i < ARRAY_SIZE(perms); i++) { \ > + if (!IS_ALIGNED(perms[i].start, SECTION_SIZE) || \ > + !IS_ALIGNED(perms[i].end, SECTION_SIZE)) { \ > + pr_err("BUG: section %lx-%lx not aligned to %lx\n", \ > + perms[i].start, perms[i].end, \ > + SECTION_SIZE); \ > + continue; \ > + } \ > + \ > + for (addr = perms[i].start; \ > + addr < perms[i].end; \ > + addr += SECTION_SIZE) \ > + section_update(addr, perms[i].mask, \ > + perms[i].field); \ > + } \ > +} > + > static inline void fix_kernmem_perms(void) > { > - unsigned long addr; > - unsigned int i; > + set_section_perms(nx_perms, prot); > +} > > - if (!arch_has_strict_perms()) > - return; > +#ifdef CONFIG_DEBUG_RODATA > +void mark_rodata_ro(void) > +{ > + set_section_perms(ro_perms, prot); > +} > > - for (i = 0; i < ARRAY_SIZE(section_perms); i++) { > - if (!IS_ALIGNED(section_perms[i].start, SECTION_SIZE) || > - !IS_ALIGNED(section_perms[i].end, SECTION_SIZE)) { > - pr_err("BUG: section %lx-%lx not aligned to %lx\n", > - section_perms[i].start, section_perms[i].end, > - SECTION_SIZE); > - continue; > - } > +void set_kernel_text_rw(void) > +{ > + set_section_perms(ro_perms, clear); > +} You need a TLB flush. I had a flush_tlb_all() in my example patch, http://lists.infradead.org/pipermail/linux-arm-kernel/2014-April/244335.html, but the following is probably nicer (on top of this patch): diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c index 9bea524..a92c45a 100644 --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c @@ -741,6 +741,8 @@ static inline bool arch_has_strict_perms(void) addr += SECTION_SIZE) \ section_update(addr, perms[i].mask, \ perms[i].field); \ + \ + flush_tlb_kernel_range(perms[i].start, perms[i].end); \ } \ }