linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: Szabolcs Nagy <szabolcs.nagy@arm.com>
Cc: libc-alpha@sourceware.org, Mark Rutland <mark.rutland@arm.com>,
	Will Deacon <will@kernel.org>,
	linux-kernel@vger.kernel.org,
	Jeremy Linton <jeremy.linton@arm.com>,
	Mark Brown <broonie@kernel.org>,
	kernel-hardening@lists.openwall.com,
	Topi Miettinen <toiwoton@gmail.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2 0/6] aarch64: avoid mprotect(PROT_BTI|PROT_EXEC) [BZ #26831]
Date: Thu, 3 Dec 2020 17:30:06 +0000	[thread overview]
Message-ID: <20201203173006.GH2830@gaia> (raw)
In-Reply-To: <cover.1606319495.git.szabolcs.nagy@arm.com>

Hi Szabolcs,

On Fri, Nov 27, 2020 at 01:19:16PM +0000, Szabolcs Nagy wrote:
> This is v2 of
> https://sourceware.org/pipermail/libc-alpha/2020-November/119305.html
> 
> To enable BTI support, re-mmap executable segments instead of
> mprotecting them in case mprotect is seccomp filtered.
> 
> I would like linux to change to map the main exe with PROT_BTI when
> that is marked as BTI compatible. From the linux side i heard the
> following concerns about this:
> - it's an ABI change so requires some ABI bump. (this is fine with
>   me, i think glibc does not care about backward compat as nothing
>   can reasonably rely on the current behaviour, but if we have a
>   new bit in auxv or similar then we can save one mprotect call.)

I'm not concerned about the ABI change but there are workarounds like a
new auxv bit.

> - in case we discover compatibility issues with user binaries it's
>   better if userspace can easily disable BTI (e.g. removing the
>   mprotect based on some env var, but if kernel adds PROT_BTI and
>   mprotect is filtered then we have no reliable way to remove that
>   from executables. this problem already exists for static linked
>   exes, although admittedly those are less of a compat concern.)

This is our main concern. For static binaries, the linker could detect,
in theory, potential issues when linking and not set the corresponding
ELF information.

At runtime, a dynamic linker could detect issues and avoid enabling BTI.
In both cases, it's a (static or dynamic) linker decision that belongs
in user-space.

> - ideally PROT_BTI would be added via a new syscall that does not
>   interfere with PROT_EXEC filtering. (this does not conflict with
>   the current patches: even with a new syscall we need a fallback.)

This can be discussed as a long term solution.

> - solve it in systemd (e.g. turn off the filter, use better filter):
>   i would prefer not to have aarch64 (or BTI) specific policy in
>   user code. and there was no satisfying way to do this portably.

I agree. I think the best for now (as a back-portable glibc fix) is to
ignore the mprotect(PROT_EXEC|PROT_BTI) error that the dynamic loader
gets. BTI will be disabled if MDWX is enabled.

In the meantime, we should start (continue) looking at a solution that
works for both systemd and the kernel and be generic enough for other
architectures. The stateless nature of the current SECCOMP approach is
not suitable for this W^X policy. Kees had some suggestions here but the
thread seems to have died:

https://lore.kernel.org/kernel-hardening/202010221256.A4F95FD11@keescook/

-- 
Catalin

  parent reply	other threads:[~2020-12-03 17:30 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-27 13:19 [PATCH v2 0/6] aarch64: avoid mprotect(PROT_BTI|PROT_EXEC) [BZ #26831] Szabolcs Nagy
2020-11-27 13:19 ` [PATCH v2 1/6] aarch64: Fix missing BTI protection from dependencies [BZ #26926] Szabolcs Nagy
2020-12-10 17:51   ` Adhemerval Zanella
2020-12-11 15:33     ` Szabolcs Nagy
2020-11-27 13:20 ` [PATCH v2 2/6] elf: lose is closely tied to _dl_map_object_from_fd Szabolcs Nagy
2020-11-27 13:20 ` [PATCH v2 3/6] elf: Fix failure handling in _dl_map_object_from_fd Szabolcs Nagy
2020-12-10 18:25   ` Adhemerval Zanella
2020-12-11  9:32     ` Szabolcs Nagy
2020-11-27 13:20 ` [PATCH v2 4/6] elf: Move note processing after l_phdr is updated Szabolcs Nagy
2020-11-27 13:21 ` [PATCH v2 5/6] elf: Pass the fd to note processing Szabolcs Nagy
2020-12-10 18:35   ` Adhemerval Zanella
2020-11-27 13:21 ` [PATCH v2 6/6] aarch64: Use mmap to add PROT_BTI instead of mprotect [BZ #26831] Szabolcs Nagy
2020-12-02  8:55   ` [PATCH v3 1/2] aarch64: align address for BTI protection [BZ #26988] Szabolcs Nagy
2020-12-10 18:49     ` Adhemerval Zanella
2020-12-02  8:55   ` [PATCH v3 2/2] aarch64: Use mmap to add PROT_BTI instead of mprotect [BZ #26831] Szabolcs Nagy
2020-12-10 19:12     ` Adhemerval Zanella
2020-11-30 15:56 ` [PATCH v2 0/6] aarch64: avoid mprotect(PROT_BTI|PROT_EXEC) " Szabolcs Nagy
2020-12-03 17:30 ` Catalin Marinas [this message]
2020-12-07 20:03   ` Szabolcs Nagy
2020-12-11 17:46     ` Catalin Marinas

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=20201203173006.GH2830@gaia \
    --to=catalin.marinas@arm.com \
    --cc=broonie@kernel.org \
    --cc=jeremy.linton@arm.com \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=szabolcs.nagy@arm.com \
    --cc=toiwoton@gmail.com \
    --cc=will@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 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 NNTP newsgroup(s).