Re: [patch] mmap() MAP_TEXT implementation (to use for shared libraries)

From: Svatopluk Kraus <onwahe_at_gmail.com>
Date: Mon, 1 Oct 2012 17:11:34 +0200
On Fri, Sep 7, 2012 at 9:40 PM, John Baldwin <jhb_at_freebsd.org> wrote:
> On Friday, September 07, 2012 2:41:20 pm Konstantin Belousov wrote:
>> > I think these would be rare?  There's no good reason for anything to write to
>> > a shared library that I can think of.  install(1) does an atomic rename to swap
>> > in the new libraries already.
>>
>> After a second thought, I do not like your proposal as well. +x is set for
>> shebang scripts, and allowing PROT_EXEC to set VV_TEXT for them means
>> that such scripts are subject for write denial.
>
> Yeah, that's fair.  Also, I hunted around to find the description of MAP_TEXT
> in Solaris 11.  It seems from reading that that MAP_TEXT on Solaris isn't used
> to prevent writes ala VV_TEXT.  Instead, it is used as a hint that is
> apparently used to use superpages for text.
>
> --
> John Baldwin

Hi,

  I'd like to finish this thread somehow. For security sake, it looks
that bounding VV_TEXT with MAP_TEXT is not good idea. Now, I see only
two possibilities how to solve the shared libraries issue in general.

  1. To have one more permission flag, first for files on which
VV_TEXT can be set and second for files on which VV_TEXT may not be
set.

  2. To activate shared libraries in kernel.

  The whole situation is following.

  There are two basic kinds of binaries in system. The first ones only
need to be activated, the second ones need to be interpreted by an
interpreter which is activated already. While activation is a concern
of kernel and should be done in kernel, an interpretation is a concern
of an interpreter and as such is done in userland. Unfortunately, even
so different in nature, both share x+ permission and can't be
distinguished by it.

  The shared libraries issue is that even they can be activated only,
they are interpreted by dynamic linker instead. As VV_TEXT is kernel
flag and can be set safely by kernel only, there is no way how to
protect them by the flag in this situation.

       Svata
Received on Mon Oct 01 2012 - 13:11:37 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:31 UTC