mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rich Felker <dalias@libc.org>
To: David Daney <ddaney@caviumnetworks.com>
Cc: David Daney <ddaney.cavm@gmail.com>,
	libc-alpha@sourceware.org, linux-kernel@vger.kernel.org,
	linux-mips@linux-mips.org, David Daney <david.daney@cavium.com>
Subject: Re: [PATCH resend] MIPS: Allow FPU emulator to use non-stack area.
Date: Mon, 6 Oct 2014 19:08:56 -0400	[thread overview]
Message-ID: <20141006230856.GC23797@brightrain.aerifal.cx> (raw)
In-Reply-To: <543314DF.20808@caviumnetworks.com>

On Mon, Oct 06, 2014 at 03:17:03PM -0700, David Daney wrote:
> >>Furthermore the
> >>userspace code has to be very careful in its use of the $sp
> >>register, so that it doesn't store data in places that will be
> >>used/clobbered by the kernel.
> >
> >This is not "being careful". The stack pointer can never become
> >invalid unless you do wacky things in asm or invoke UB.
> >
> >>All of this is under the control of the userspace program and done
> >>with userspace code.
> >
> >For the most part it just happens by default. There is no particular
> >intentionality needed, and certainly no hideous MIPS-specific hacks
> >needed.
> 
> Yes, it happens by default.  But it wasn't magic.  It took careful
> work by the ABI and toolchain designers to make it work.

Here I disagree. All of these things are completely universal, not
MIPS-specific.

> >>I appreciate the fact that libc authors might prefer *not* to write
> >>more code, but they could, especially if they wanted to add the
> >>feature of non-executable stacks to their library implementation.
> >
> >So your position is that:
> 
> It is not really a position that I have.  Rather a proposal for one
> possible way to make non-executable stacks work on MIPS.
> 
> >
> >1. A non-exec-stack system can only run new code produced to do extra
> >    stuff in userspace.
> 
> Any non-executable stack solution for MIPS will require changes to
> the toolchain/libc.  So it is merely a question of what form the
> change should take.

I disagree with this, at least for the most part. If the kernel does
the fpu emulation correctly, there's no reason it shouldn't be
possible to run existing binaries on a hardened kernel that does not
even support executable stack.

> >2. The startup code needs to do special work in userspace on MIPS to
> >    setup an executable area for fpu emulation.
> 
> Yes. Similar to how startup code has to do special work to set up
> the TLS areas,

Yes. Actually the simple way to implement this in userspace would be
with a page-sized, page-aligned object in TLS and a special call to
mprotect and your new syscall. One thing I'm not clear on: should this
memory have permissions r-x or rwx? If it has rwx, that defeats a lot
of the purpose of non-executable-stack. Hopefully it's r-x and the
kernel bypasses the non-writability to write to it.

> and load shared libraries.

Dynamic linking is completely a separate matter. Not all programs are
even dynamic-linked.

> >3. Every call to clone/CLONE_VM needs to be accompanied by a call to
> >    mmap and this new syscall to set the address, and every call to
> >    SYS_exit needs to be accompanies by a call to munmap for the
> >    corresponding mapping.
> >
> 
> No, We don't have to mmap() on each thread creation.  Many threads
> (perhaps 512) could be handled by a single page, so the normal case
> would be a single mmap() for the life of the program.

That's nice from a standpoint of avoiding memory waste, but it's
problematic if .////

> >This is a huge ill-designed mess.
> >
> 
> Have you seen the alternatives?

I proposed a couple and I think they're much less ugly. Could you
point me to the others?

But perhaps you could clarify one thing for me: why is any of this
even needed? A delay slot only exists for branch instructions, and I
can't see any reason the kernel can't just emulate the branch
instruction at the same time. This is a very restricted class of
instructions that should not require any complex emulation of memory
permissions, just manipulation of the resulting program counter value
after the floating point instruction finishes. Or am I missing
something?

> Have you ever wondered why MIPS doesn't have non-executable stack support?

I wasn't even aware that it didn't until your email.

Rich

  reply	other threads:[~2014-10-06 23:10 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-06 20:23 David Daney
2014-10-06 20:54 ` Rich Felker
2014-10-06 21:18   ` David Daney
2014-10-06 21:31     ` Rich Felker
2014-10-06 21:45       ` David Daney
2014-10-06 21:58         ` Rich Felker
2014-10-06 22:17           ` David Daney
2014-10-06 23:08             ` Rich Felker [this message]
2014-10-06 23:38           ` Andy Lutomirski
2014-10-06 23:48             ` David Daney
2014-10-06 23:54               ` Andy Lutomirski
2014-10-07  0:05               ` Rich Felker
2014-10-07  0:11                 ` Andrew Pinski
2014-10-07  0:21                   ` Rich Felker
2014-10-07  0:28                     ` Andrew Pinski
2014-10-07  0:29                       ` Andy Lutomirski
2014-10-07  0:32                         ` David Daney
2014-10-07  0:33                 ` David Daney
2014-10-07  0:48                   ` Andy Lutomirski
2014-10-07  0:49                   ` Rich Felker
2014-10-07  4:50                     ` David Daney
2014-10-07  9:13                       ` Matthew Fortune
2014-10-07 10:52                         ` James Hogan
2014-10-07 11:19                         ` Rich Felker
2014-10-07 16:04                         ` David Daney
2014-10-07 18:32                         ` Leonid Yegoshin
2014-10-07 18:43                           ` David Daney
2014-10-07 19:13                             ` Leonid Yegoshin
2014-10-07 18:44                           ` Andy Lutomirski
2014-10-07 18:50                             ` David Daney
2014-10-07 19:09                             ` Rich Felker
2014-10-07 19:16                               ` Leonid Yegoshin
2014-10-07 19:21                                 ` Rich Felker
2014-10-07 19:27                                   ` Leonid Yegoshin
2014-10-07 19:28                                   ` Andy Lutomirski
2014-10-07 20:03                                     ` David Daney
2014-10-08  0:22                                       ` Andy Lutomirski
2014-10-07 19:40                             ` Matthew Fortune
2014-10-07 11:11                       ` Rich Felker
2014-10-07 16:08                         ` David Daney
2014-10-07 18:16                           ` Andy Lutomirski
2014-10-07 23:20     ` Ralf Baechle
2014-10-07 23:59       ` David Daney
2014-10-08  0:18         ` Chuck Ebbert
2014-10-08  2:37           ` Rich Felker
2014-10-08 10:31         ` Paul Burton
2014-10-07  1:02 ` Kevin D. Kissell
2014-10-07  1:38   ` Rich Felker
2014-10-07  4:32   ` David Daney
2014-10-07 11:53     ` James Hogan
2014-10-07 12:22       ` James Hogan

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=20141006230856.GC23797@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=david.daney@cavium.com \
    --cc=ddaney.cavm@gmail.com \
    --cc=ddaney@caviumnetworks.com \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-kernel@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®