All of lore.kernel.org
 help / color / mirror / Atom feed
From: daw@cs.berkeley.edu (David Wagner)
To: linux-kernel@vger.kernel.org
Subject: Re: [patch] remove MNT_NOEXEC check for PROT_EXEC MAP_PRIVATE mmaps
Date: Fri, 29 Sep 2006 01:41:34 +0000 (UTC)	[thread overview]
Message-ID: <efhtke$h5d$2@taverner.cs.berkeley.edu> (raw)
In-Reply-To: Pine.LNX.4.64.0609281707190.27484@blonde.wat.veritas.com

Ok, I've had a chance to look into this in a little more detail, and
I have now come to a different view.  Although I think Stas's proposal
is well-motivated, I'm now more skeptical about some of the details of
his proposal.  Here is my current thinking on this issue:

1) It is important that when ld.so has some way to ensure that executing
a program off of a noexec partition will fail.  The details of how it
does that don't matter, from a security point of view, though they do
matter from a maintenance perspective.  If Stas's proposal requires
changes to ld.so, Stas should implement and test those changes before
any changes are made to the kernel.

2) Currently, ld.so uses mmap(PROT_EXEC, MAP_PRIVATE) to load the text
of the programs it executes.  Consequently, if we want to avoid changing
ld.so, then we need mmap(PROT_EXEC, MAP_PRIVATE) to fail with an error
if the text lives on a noexec partition.

3) I think it's a requirement that any change to Linux mmap() semantics
will not break ld.so's noexec check.

4) Everything else about the way the Linux kernel handles mmap(PROT_EXEC)
is not security-critical.  As long as ld.so will refuse to execute
a program that lives on a noexec partition, you can choose the rest
of mmap()'s semantics any way you want without fear of introducing a
security loophole.

5) There are already a million-and-one loopholes that allow one to
indirectly execute code that lives on a noexec partition.  For instance,
one can run 'perl ld-linux.ignore-noexec.so'.  As another example, one
can use mmap(PROT_EXEC, MAP_ANONYMOUS) to create an executable region
of memory, then use read() to read the text in from a noexec partition
and copy it into the executable region, and then jump to the executable
region of memory.  It would be trivial to write a replacement for ld.so's
mmap(PROT_EXEC, MAP_PRIVATE) that has the same effect except that it
ignores the noexec flag.  There is no way to close all of these loopholes.

6) In general, it's easy to see that as long as a program can create any
region of memory that is both executable and writeable, there will always
be a loophole.  There's no way we are going to write a prohibition into
the kernel saying that no program can ever have a region of memory that
is simultaneously executable and writeable.  Given that there are already
zillions of loopholes, adding one more loophole just doesn't matter.
Consequently, as long as we preserve the behavior of ld.so, the rest of
the semantics of mmap() can be freely changed without fear of introducing
a new security hole.

7) For instance, you could imagine adding a MAP_IREALLYMEANIT flag which
tells mmap() to ignore the noexec prohibition.  This would be safe to add,
from a security point of view (it wouldn't create any new vulnerabilities,
as long as the user code knows what it is doing when it sets this flag).
If Stas has a small set of userlevel programs (wine, UML, etc.) that need
the ability to link in libraries that live on noexec partitions, then this
would provide a safe way to meet this need in a backwards-compatible way.
Of course, Stas would have to go patch those userlevel programs himself
to add the MAP_IREALLYMEANIT flag, but that's his problem.

8) The value of noexec is proportional to the number of partitions that
you can mount with the noexec flag enabled.  If the noexec semantics are
tightened down so strictly that you can't enable noexec on any mount
(because otherwise too many userlevel programs break), then the value
of noexec is nil.  If loosening the noexec restrictions slightly allows
you to mark more partitions as noexec, then this is a net win (assuming
that ld.so continues to reject programs that live on noexec partitions).

9) Stas's request is a request for a change to Linux kernel semantics.
The current mmap() semantics have been there for years.  We're not talking
about some recent change to mmap() semantics that have broken existing
userspace tools.  Rather, we have a longstanding set of semantics; Stas
wants to be able to mark more partitions as noexec, and he is requesting
a change to the semantics to do so.  (I have to apologize; I see that
this was obvious to everyone else, but I somehow failed to understand
this part.)  Stas's proposed change is well-motivated and I'm inclined
to be sympathetic to the motivation behind it.  Nonetheless, there is
an philosophy that changes to existing kernel semantics have to be well
justified, and in borderline cases, it is perfectly reasonable for the
maintainers to reject such a patch.  The burden is on the proposer of
the change to make a compelling case for the change.

10) At a minimum, if Stas wants to propose a change, he should test his
proposed change to make sure that they don't break ld.so's noexec check.
I can't tell whether Stas has done that.  I don't see any evidence that
he has.  Based on my description of ld.so in point 2) above, I would
expect Stas's patches to break ld.so.  If this is correct, then I think
the current patch is unacceptable and needs to be re-thought.

11) Given all of this, I've changed my mind.  I think it may be premature
to accept this patch, and the negative reactions from others seem entirely
reasonable to me.  I think Stas probably has some more work to do if he
wants to push this patch.

  reply	other threads:[~2006-09-29  1:41 UTC|newest]

Thread overview: 97+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-23 10:30 [patch] remove MNT_NOEXEC check for PROT_EXEC mmaps Stas Sergeev
2006-09-23 15:16 ` Hugh Dickins
2006-09-23 15:36   ` Ulrich Drepper
2006-09-23 15:47     ` Stas Sergeev
2006-09-25  1:12       ` Valdis.Kletnieks
2006-09-25  4:35         ` Stas Sergeev
2006-09-23 15:42   ` Stas Sergeev
2006-09-23 16:04     ` Hugh Dickins
2006-09-23 16:38       ` Stas Sergeev
2006-09-23 18:58       ` Alan Cox
2006-09-24  6:55         ` Stas Sergeev
2006-09-24  9:17           ` Hugh Dickins
2006-09-24 10:00             ` Stas Sergeev
2006-09-24 13:53           ` Alan Cox
2006-09-24 14:54             ` Stas Sergeev
2006-09-24 15:48               ` Ulrich Drepper
2006-09-24 16:31                 ` Stas Sergeev
2006-09-24 16:49                   ` Ulrich Drepper
2006-09-24 17:04                     ` Stas Sergeev
2006-09-24 18:09                     ` Stas Sergeev
2006-09-24 19:14                       ` David Wagner
2006-09-24 19:37                         ` Kyle Moffett
2006-09-24 22:49                           ` David Wagner
2006-09-25 10:53                         ` Pavel Machek
2006-09-25 21:36                           ` David Wagner
2006-09-27 11:51                             ` Pavel Machek
2006-09-24 20:06                       ` Denis Vlasenko
2006-09-24 20:22                         ` Stas Sergeev
2006-09-24 23:04                         ` David Wagner
2006-09-26 19:46                     ` Stas Sergeev
2006-09-27 22:33                       ` Arjan van de Ven
2006-09-27 23:10                         ` David Wagner
2006-09-27 23:38                           ` Jesper Juhl
2006-09-29  1:14                             ` David Wagner
2006-09-28  4:52                         ` Stas Sergeev
2006-09-30  9:42                         ` Stas Sergeev
2006-10-03 15:01                           ` Arjan van de Ven
2006-10-03 17:15                             ` Stas Sergeev
2006-10-03 17:23                               ` Ulrich Drepper
2006-10-03 18:06                                 ` Stas Sergeev
2006-10-03 19:19                                   ` Ulrich Drepper
2006-10-03 19:40                                     ` Stas Sergeev
2006-10-03 19:54                                       ` Arjan van de Ven
2006-10-04 19:36                                         ` Stas Sergeev
2006-10-04 21:31                                           ` David Wagner
2006-10-04  3:11                                     ` David Wagner
2006-10-04  3:51                                       ` Ulrich Drepper
2006-10-04  4:21                                         ` David Wagner
2006-10-04  6:03                                           ` Kyle Moffett
2006-10-04 17:30                                           ` Ulrich Drepper
2006-10-03 18:23                               ` Arjan van de Ven
2006-10-03 18:40                                 ` Stas Sergeev
2006-10-03 18:42                                   ` Arjan van de Ven
2006-10-03 19:07                                     ` Stas Sergeev
2006-10-03 21:00                                       ` Jakub Jelinek
2006-10-04 19:06                                         ` Stas Sergeev
2006-10-06 18:09                                           ` [patch] honour MNT_NOEXEC for access() Stas Sergeev
2006-10-06 21:34                                             ` Alan Cox
2006-10-06 21:17                                               ` Ulrich Drepper
2006-10-07 11:19                                                 ` Stas Sergeev
2006-10-07 15:00                                                   ` David Wagner
2006-10-07 16:31                                                   ` Ulrich Drepper
2006-10-07 19:14                                                     ` Stas Sergeev
2006-10-07 19:36                                                       ` David Wagner
2006-10-08  8:32                                                       ` Arjan van de Ven
2006-10-08  9:11                                                         ` Stas Sergeev
2006-10-08 10:55                                                           ` Arjan van de Ven
2006-10-08 13:46                                                             ` Stas Sergeev
2006-10-09  2:09                                                           ` Horst H. von Brand
2006-10-09  4:40                                                             ` Stas Sergeev
2006-10-07 13:18                                               ` Stas Sergeev
2006-10-08  0:30                                                 ` Jeremy Fitzhardinge
2006-10-08  9:10                                                   ` Stas Sergeev
2006-10-08  9:56                                                     ` Jeremy Fitzhardinge
2006-10-08 10:36                                                       ` Stas Sergeev
2006-10-08 10:39                                                       ` Jesper Juhl
2006-10-08 13:22                                                         ` Stas Sergeev
2006-10-06 22:26                                             ` Jesper Juhl
2006-10-04 19:30                                         ` [patch] remove MNT_NOEXEC check for PROT_EXEC mmaps Stas Sergeev
2006-10-04  3:20                                       ` David Wagner
2006-10-04  3:17                               ` David Wagner
2006-10-04 13:41                                 ` Jeff Dike
2006-10-04 18:02                               ` Jesper Juhl
2006-10-04 19:48                                 ` Stas Sergeev
2006-09-27 19:16                     ` [patch] remove MNT_NOEXEC check for PROT_EXEC MAP_PRIVATE mmaps Stas Sergeev
2006-09-27 20:05                       ` Hugh Dickins
2006-09-28  4:33                         ` Stas Sergeev
2006-09-28 16:42                           ` Hugh Dickins
2006-09-29  1:41                             ` David Wagner [this message]
2006-09-29 20:50                               ` Arjan van de Ven
2006-09-29 16:54                             ` Stas Sergeev
2006-09-24 19:59                   ` [patch] remove MNT_NOEXEC check for PROT_EXEC mmaps Alan Cox
2006-09-24 20:07                     ` Stas Sergeev
2006-09-24  0:53 ` Arjan van de Ven
2006-09-25 17:17   ` Stas Sergeev
2006-09-25 17:43   ` Stas Sergeev
2006-09-25 20:12   ` David Wagner

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='efhtke$h5d$2@taverner.cs.berkeley.edu' \
    --to=daw@cs.berkeley.edu \
    --cc=daw-usenet@taverner.cs.berkeley.edu \
    --cc=linux-kernel@vger.kernel.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.