[Top] [All Lists]

Re: [PATCH v2] MIPS: Add nonxstack=on|off kernel parameter

To: Miodrag Dinic <>, James Hogan <>
Subject: Re: [PATCH v2] MIPS: Add nonxstack=on|off kernel parameter
From: David Daney <>
Date: Fri, 1 Dec 2017 09:38:20 -0800
Authentication-results: spf=none (sender IP is );
Cc: Aleksandar Markovic <>, "" <>, Aleksandar Markovic <>, Andrew Morton <>, DengCheng Zhu <>, Ding Tianhong <>, Douglas Leung <>, Frederic Weisbecker <>, Goran Ferenc <>, Ingo Molnar <>, James Cowgill <>, Jonathan Corbet <>, "" <>, "" <>, Marc Zyngier <>, Matt Redfearn <>, Mimi Zohar <>, Paul Burton <>, "Paul E. McKenney" <>, Petar Jovanovic <>, Raghu Gandham <>, Ralf Baechle <>, Thomas Gleixner <>, Tom Saeger <>
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed;; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=IGKj7UexG+a5w0+r6nIY6t/6igrPamG6rqz/JAHnqnE=; b=HacDo2fSJ9ozPN6SBOqmCnHS84MQ3sMAeh/Zd1UOF6NDblGSdHgzj35v96ySQliPRyxYc0GZI2EJxtbLxzBL21S+1xz8uQvTwyyooBhFzssQjElPqX81uGe4TbzyAbMe61vs376ESahva6mXk/+ASZlMpsNAcpV6dmNweMVNUtI=
In-reply-to: <>
List-archive: <>
List-help: <>
List-id: linux-mips <>
List-owner: <>
List-post: <>
List-software: Ecartis version 1.0.0
List-subscribe: <>
List-unsubscribe: <>
Original-recipient: rfc822;
References: <> <> <> <> <>
Spamdiagnosticmetadata: NSPM
Spamdiagnosticoutput: 1:99
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0
On 11/30/2017 05:06 AM, Miodrag Dinic wrote:
Hi James,

We do have PT_GNU_STACK flags set correctly, this feature is required to
workaround CPU revisions which do not have RIXI support.

RIXI support can be discovered programatically from CP0_Config3.RXI
(cpu_has_rixi in asm/cpu-features.h), so I don't follow why CPUs without
RIXI would require a kernel parameter.

The following patch introduced change in behavior with regards to
stack & heap execute-ability :
commit 1a770b85c1f1c1ee37afd7cef5237ffc4c970f04
Author: Paul Burton <>
Date:   Fri Jul 8 11:06:20 2016 +0100

     MIPS: non-exec stack & heap when non-exec PT_GNU_STACK is present
The stack and heap have both been executable by default on MIPS until
     now. This patch changes the default to be non-executable, but only for
     ELF binaries with a non-executable PT_GNU_STACK header present. This
     does apply to both the heap & the stack, despite the name PT_GNU_STACK,
     and this matches the behaviour of other architectures like ARM & x86.
Current MIPS toolchains do not produce the PT_GNU_STACK header, which
     means that we can rely upon this patch not changing the behaviour of
     existing binaries. The new default will only take effect for newly
     compiled binaries once toolchains are updated to support PT_GNU_STACK,
     and since those binaries are newly compiled they can be compiled
     expecting the change in default behaviour. Again this matches the way in
     which the ARM & x86 architectures handled their implementations of
     non-executable memory.
Signed-off-by: Paul Burton <>
     Cc: Leonid Yegoshin <>
     Cc: Maciej Rozycki <>
     Cc: Faraz Shahbazker <>
     Cc: Raghu Gandham <>
     Cc: Matthew Fortune <>
     Signed-off-by: Ralf Baechle <>


When kernel is detecting the type of mapping it should apply :

        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.

All Cavium processors since OCTEON Plus (more than ten years ago) support RIXI.

We would like to have an option to override this and force non-executable 
mappings for such systems.

This is what I don't understand. If a system doesn't support XI, then no mapping can possibly be non-executable.

There may be some utility in disabling the use of the RIXI bits on systems that do support them. But no command line can conjure functional RIXI on systems that don't support it.

Also, this does nothing for multi-threaded programs where libc sets the permissions on the thread stacks.

If you really need something, at a minimum, use the same parameter name that x86 uses.

<Prev in Thread] Current Thread [Next in Thread>