From: Ralf Baechle <ralf@linux-mips.org>
To: Florian Weimer <fweimer@redhat.com>
Cc: linux-mips@linux-mips.org
Subject: Re: Endless loop on execution attempt on non-executable page
Date: Thu, 12 May 2016 14:53:42 +0200 [thread overview]
Message-ID: <20160512125342.GS16402@linux-mips.org> (raw)
In-Reply-To: <57345F0D.9070503@redhat.com>
On Thu, May 12, 2016 at 12:46:37PM +0200, Florian Weimer wrote:
> The GCC compile farm has a big-endian 64-bit MIPS box. The kernel is:
>
> Linux erpro8-fsf1 3.14.10-er8mod-00013-ge0fe977 #1 SMP PREEMPT Wed Jan
> 14 12:33:22 PST 2015 mips64 GNU/Linux
>
> Which is a vendor kernel for the EdgeRouter Pro-8.
>
> /proc/cpuinfo reports:
>
> system type : UBNT_E200 (CN6120p1.1-1000-NSP)
> machine : Unknown
> processor : 0
> cpu model : Cavium Octeon II V0.1
>
> While testing W^X (execmod, DEP, NX) stack enforcement, I noticed that once
> I try to execute code off a non-executable page, I do not get a signal, but
> the code appears to enter an infinite loop. The generated function starts
> with a jump instruction to return to the caller, but instead, the program
> counter does not seem to change at all.
>
> “si” in GDB also hangs (but can be interrupted with ^C).
>
> My test code is here:
>
> https://pagure.io/execmod-tests
>
> Is this a kernel bug or an issue with the silicon?
I see the test case uses mprotect to add PROT_EXEC after writing the code
to memory. I don't think mprotect however gives any guarantee that this
will make the I-cache coherent with the D-cache, that is that the CPU will
actually fetch and execute the instruction that were just written to memory.
For that you have to do something architecture specific such as dancing
around a fire waving a dead chicken. Or on MIPS call cacheflush(), see
the man page for details.
For portability sake to some broken processors you should also ensure
that a 32 byte cache line is entirely filled with valid instructions by
padding the two test instructions with another six no-op (opcode 0).
The test case as it is guarantees this implicitly by using a freshly
allocated page but I thought I should mention it.
Ralf
next prev parent reply other threads:[~2016-05-12 12:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-12 10:46 Endless loop on execution attempt on non-executable page Florian Weimer
2016-05-12 12:53 ` Ralf Baechle [this message]
2016-05-12 13:07 ` Florian Weimer
2016-05-12 14:23 ` Ralf Baechle
2016-05-12 15:57 ` David Daney
2016-05-17 10:15 ` Florian Weimer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160512125342.GS16402@linux-mips.org \
--to=ralf@linux-mips.org \
--cc=fweimer@redhat.com \
--cc=linux-mips@linux-mips.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.