Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752624AbdLFR4l (ORCPT ); Wed, 6 Dec 2017 12:56:41 -0500 Received: from 9pmail.ess.barracuda.com ([64.235.154.211]:57253 "EHLO 9pmail.ess.barracuda.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752034AbdLFR4h (ORCPT ); Wed, 6 Dec 2017 12:56:37 -0500 Date: Wed, 6 Dec 2017 17:50:52 +0000 From: "Maciej W. Rozycki" To: Miodrag Dinic CC: James Hogan , David Daney , Aleksandar Markovic , "linux-mips@linux-mips.org" , Aleksandar Markovic , Andrew Morton , DengCheng Zhu , Ding Tianhong , Douglas Leung , "Frederic Weisbecker" , Goran Ferenc , "Ingo Molnar" , James Cowgill , "Jonathan Corbet" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Marc Zyngier , "Matt Redfearn" , Mimi Zohar , Paul Burton , "Paul E. McKenney" , Petar Jovanovic , Raghu Gandham , Ralf Baechle , Thomas Gleixner , Tom Saeger Subject: RE: [PATCH v2] MIPS: Add nonxstack=on|off kernel parameter In-Reply-To: <48924BBB91ABDE4D9335632A6B179DD6A8D102@MIPSMAIL01.mipstec.com> Message-ID: References: <1511272574-10509-1-git-send-email-aleksandar.markovic@rt-rk.com> <48924BBB91ABDE4D9335632A6B179DD6A8CFEA@MIPSMAIL01.mipstec.com>,<20171130100957.GG5027@jhogan-linux.mipstec.com> <48924BBB91ABDE4D9335632A6B179DD6A8D102@MIPSMAIL01.mipstec.com> User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-BESS-ID: 1512582847-321459-27965-5668-6 X-BESS-VER: 2017.14-r1710272128 X-BESS-Apparent-Source-IP: 12.201.5.28 X-BESS-Outbound-Spam-Score: 0.21 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.187686 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound 0.20 PR0N_SUBJECT META: Subject has letters around special characters (pr0n) 0.01 BSF_SC0_SA_TO_FROM_DOMAIN_MATCH META: Sender Domain Matches Recipient Domain X-BESS-Outbound-Spam-Status: SCORE=0.21 using account:ESS59374 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND, PR0N_SUBJECT, BSF_SC0_SA_TO_FROM_DOMAIN_MATCH X-BESS-BRTS-Status: 1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1928 Lines: 73 Hi Miodrag, > When kernel is detecting the type of mapping it should apply : > > fs/binfmt_elf.c: > ... > if (elf_read_implies_exec(loc->elf_ex, executable_stack)) > current->personality |= READ_IMPLIES_EXEC; > ... > > this effectively calls mips_elf_read_implies_exec() which performs a check: > ... > if (!cpu_has_rixi) { > /* The CPU doesn't support non-executable memory */ > return 1; > } > > return 0; > } > > This will in turn make stack & heap executable on processors without > RIXI, which are practically all processors with MIPS ISA R < 6. > > We would like to have an option to override this and force > non-executable mappings for such systems. Of course you can't force a non-executable mapping with a system where all valid pages are executable, as David has already noted. Did you mean the other condition, that is: if (exstack != EXSTACK_DISABLE_X) { /* The binary doesn't request a non-executable stack */ return 1; } ? In which case you do want to respect the lack of the RIXI feature, i.e.: int mips_elf_read_implies_exec(void *elf_ex, int exstack) { if (!cpu_has_rixi) { /* The CPU doesn't support non-executable memory */ return 1; } switch (nonxstack) { case EXSTACK_DISABLE_X: return 0; case EXSTACK_ENABLE_X: return 1; default: break; } if (exstack != EXSTACK_DISABLE_X) { /* The binary doesn't request a non-executable stack */ return 1; } return 0; } (I'd replace `break' with `return exstack != EXSTACK_DISABLE_X' and discard the code that follows, but that can be a separate optimisation). What problem are you trying to solve anyway? Is it not something that can be handled with the `execstack' utility? NB as someone has observed with programs that do not request a non-executable stack we actually propagate the execute permission to all data pages. Is it not something we would want to handle differently? Maciej