unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Jann Horn via Libc-alpha <libc-alpha@sourceware.org>
To: Florian Weimer <fweimer@redhat.com>
Cc: Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org>,
	Jordan Abrahams <ajordanr@google.com>,
	Jorge Lucangeli Obes <jorgelo@google.com>,
	manojgupta@google.com, llozano@google.com
Subject: Re: [PATCH] Deny preload of files on NOEXEC mounts
Date: Mon, 23 Aug 2021 23:09:19 +0200	[thread overview]
Message-ID: <CAG48ez1p0E8x_PaqjP-q-6YNC53VoDsAPbeHoc9cPQKcNcwaAw@mail.gmail.com> (raw)
In-Reply-To: <87o89opff0.fsf@oldenburg.str.redhat.com>

On Mon, Aug 23, 2021 at 1:30 PM Florian Weimer <fweimer@redhat.com> wrote:
>
> * Jordan Abrahams:
>
> > In response to Alexander,
> >
> >> this is not about refusing mmap from a noexec mount, this is a counter-measure
> >> against specially crafted ELF files taking over the dynamic loader even before
> >> it attempts a PROT_EXEC mmap, as demonstrated in glibc bug #21718
> >
> > Indeed, it's not about refusing an mmap from a noexec mount. These are
> > handcrafted ELF files which take over the loader. If you would like to
> > see the proof of concept of the attack, we can add you to the allowed
> > listings for the linked bug thread
> > (https://bugs.chromium.org/p/chromium/issues/detail?id=1182687). We
> > have an ELF for x86_64 devices which shows the above behaviour on our
> > current kernel of ChromeOS. I'm uncertain of the status of other OSes
> > (I would need to reach out again to our security team), but I doubt it
> > would be restricted to just ChromeOS.
>
> There have been public discussions about such bugs before, not sure why
> you are restricting it.
>
> I expect that it will always be possible to take over the dynamic loader
> until we are more restrictive when it comes to use of MAP_FIXED in the
> loader, probably by using MAP_FIXED_NOREPLACE.  The challenge is to make
> the change so conservative that existing (slightly broken, or ia64)
> binaries are not impacted.

My understanding is that the ChromeOS security folks (I'm not on that
team) would like to ensure that, as a security hardening measure,
attempting to load an attacker-controlled library from a noexec mount
doesn't give the attacker the ability to run code in the context of
the loader.

As far as I understand, the kind of ELF file I used in the linked bug
(sorry about the access restriction) looks fairly legitimate: It
doesn't clobber any existing mappings, instead it uses a ".init_array"
section containing a relocation into glibc, like this:

        .section        .init_array,"aw"
        .align 8
        .quad   rmdir+0x774

By picking an appropriate gadget in glibc, and making use of the
register contents at the indirect call to the fake constructor
function, it is possible to use that to e.g. start a ROP chain.


I think there are also more fundamental things that a library without
any executable segments could do, by design, to compromise the
integrity of the process - e.g. depending on when the evil library is
loaded, it might be able to override a pointer symbol that was
supposed to be located in a ".bss" section to point at the evil
library's ".data" section instead and use that to effectively clobber
a NULL-initialized pointer variable with an arbitrary value, or
something like that?

This is why I think that as long as you accept the premise that NOEXEC
should robustly prevent library loading, the loader (possibly in
collaboration with the kernel) has to ensure that even libraries
without executable segments cannot be loaded from non-executable
files.

(Btw, this also means that IMA-based auditing of library loading based
on executable mappings is currently bypassable. I don't think anyone
really cares about that though - I brought it up with the IMA
maintainers back in 2018 and IIRC they didn't see it as a problem.)

  parent reply	other threads:[~2021-08-23 21:10 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-19 19:33 [PATCH] Deny preload of files on NOEXEC mounts Jordan R Abrahams via Libc-alpha
2021-07-23 18:38 ` Adhemerval Zanella via Libc-alpha
2021-07-23 19:22   ` Florian Weimer via Libc-alpha
2021-07-23 20:42     ` Adhemerval Zanella via Libc-alpha
2021-07-23 20:50       ` Florian Weimer via Libc-alpha
2021-07-23 21:17         ` Adhemerval Zanella via Libc-alpha
2021-07-23 21:27           ` Alexander Monakov via Libc-alpha
2021-07-23 22:14             ` Jordan Abrahams via Libc-alpha
2021-08-23 11:29               ` Florian Weimer via Libc-alpha
2021-08-23 19:13                 ` Jordan Abrahams via Libc-alpha
2021-08-23 21:09                 ` Jann Horn via Libc-alpha [this message]
2021-09-06 15:10                   ` Florian Weimer via Libc-alpha
2021-09-06 21:48                     ` Mike Frysinger via Libc-alpha
2021-08-23 23:40                 ` Cristian Rodríguez
2021-08-24 12:00                   ` Adhemerval Zanella via Libc-alpha
2021-07-23 23:59             ` Adhemerval Zanella via Libc-alpha

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

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAG48ez1p0E8x_PaqjP-q-6YNC53VoDsAPbeHoc9cPQKcNcwaAw@mail.gmail.com \
    --to=libc-alpha@sourceware.org \
    --cc=ajordanr@google.com \
    --cc=fweimer@redhat.com \
    --cc=jannh@google.com \
    --cc=jorgelo@google.com \
    --cc=llozano@google.com \
    --cc=manojgupta@google.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).