mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Szabolcs Nagy <nsz@port70.net>
To: Rich Felker <dalias@libc.org>
Cc: musl@lists.openwall.com
Subject: Re: [musl] mallocng switchover - opportunity to test
Date: Tue, 9 Jun 2020 13:09:14 +0200	[thread overview]
Message-ID: <20200609110914.GC871552@port70.net> (raw)
In-Reply-To: <20200609035010.GE1079@brightrain.aerifal.cx>

* Rich Felker <dalias@libc.org> [2020-06-08 23:50:10 -0400]:
> This produces a near-fully-integrated malloc, including support for
> reclaim_gaps donation from ldso. The only functionality missing, which
> I expect to flesh out before actual import, is handling of the case of
> incomplete malloc replacement by interposition (__malloc_replaced!=0).

i would actually prefer if we didn't check for __malloc_replaced
in aligned alloc, because i think it does not provide significant
safety, but it prevents the simple RTLD_NEXT wrappers which are
commonly used for simple malloc debugging/tracing/etc (and while
unsafe in general depending on what libc api calls they make,
they likely work in practice).

(the check does not provide safety because existing interposers
written for glibc likely work with musl too without issues:
the only problem is if musl uses aligned alloc somewhere where
glibc does not so an interposer may work on glibc without
interposing aligned alloc but not on musl. for newly written
interposers we just need to document the api contract.)

fyi, i looked at enabling AArch64 MTE in malloc ng, with the
current linux syscall abi patches i saw the following issues:

- brk is not usable (this might change in the final linux patches
  but it's nice that we can turn brk usage off in malloc-ng)

- reclaim_gaps is not usable (in linux, file content may be in
  memory that does not support mte, even for private CoW maps,
  this can be changed in principle but to use reclaim_gaps elf
  changes will be needed anyway so a loader knows it has to
  use PROT_MTE and there is no elf abi design for that yet)

- meta data at the end of an allocation slot cannot share the
  same tagging granule (16byte) with user allocation (otherwise
  accessing it would become akward due to possible concurrent
  tag changes, even if we don't care about protecting that meta
  data with mte) hence 16 bytes has to be reserved for meta data,
  this impacts the overhead of small allocations (the required
  code change is small given it already uses 16byte units, but
  since the layout of allocations is affected this is probably
  the most intrusive change mte requires).

- madvise MADV_FREE means naive tagging of internal/freed memory
  with a reseved internal tag does not work: internal pointers
  cannot access memory after they are zeroed by the kernel.
  this can be fixed in various ways i haven't decided what's
  best yet. enabling mte will cause various regressions and
  different behaviour (e.g. because all pages are written to on
  malloc, calloc, realloc, free) this will be one of them.

if support for this is interesting i can work on patches
that can be upstreamed (e.g. macros conditional on mte
support etc)

  reply	other threads:[~2020-06-09 11:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-09  3:50 Rich Felker
2020-06-09 11:09 ` Szabolcs Nagy [this message]
2020-06-09 20:08   ` Rich Felker
2020-06-10  0:58     ` Rich Felker
2020-06-10  8:33       ` Szabolcs Nagy
2020-06-11 20:05         ` Rich Felker
2020-06-12 17:42           ` Szabolcs Nagy
2020-06-10  9:19     ` Szabolcs Nagy
2020-06-10 16:41       ` Rich Felker
2020-06-11  3:49 ` Rich Felker
2020-06-11  4:33   ` Rich Felker

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=20200609110914.GC871552@port70.net \
    --to=nsz@port70.net \
    --cc=dalias@libc.org \
    --cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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).