<feed xmlns='http://www.w3.org/2005/Atom'>
<title>delta/glibc.git/malloc, branch arm/morello/main</title>
<subtitle>sourceware.org: git/glibc.git
</subtitle>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/glibc.git/'/>
<entry>
<title>cheri: malloc: exact capability check in free/realloc</title>
<updated>2023-04-05T14:29:59+00:00</updated>
<author>
<name>Szabolcs Nagy</name>
<email>szabolcs.nagy@arm.com</email>
</author>
<published>2023-04-04T15:39:34+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/glibc.git/commit/?id=33cb9de5cba0e3b428a2bab4bd8368bf55806430'/>
<id>33cb9de5cba0e3b428a2bab4bd8368bf55806430</id>
<content type='text'>
Capability narrowing uses a lookup table from an address to the
internally used wide capability. Keep the narrow capability in the
table instead of just the address and check it. This allows free
and realloc to check their input and only accept capabilities
exactly matching what was returned by malloc.

When a user adds restrictions on top of malloc returned capabilities
(e.g. narrower bounds), realloc could bypass those restrictions when
it simply looked up the internal wide capability for the address.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Capability narrowing uses a lookup table from an address to the
internally used wide capability. Keep the narrow capability in the
table instead of just the address and check it. This allows free
and realloc to check their input and only accept capabilities
exactly matching what was returned by malloc.

When a user adds restrictions on top of malloc returned capabilities
(e.g. narrower bounds), realloc could bypass those restrictions when
it simply looked up the internal wide capability for the address.
</pre>
</div>
</content>
</entry>
<entry>
<title>cheri: malloc: Use memcpy for obstack internal copy</title>
<updated>2023-01-06T10:03:51+00:00</updated>
<author>
<name>Szabolcs Nagy</name>
<email>szabolcs.nagy@arm.com</email>
</author>
<published>2023-01-05T18:12:36+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/glibc.git/commit/?id=807b692012ae921ac388cb2ea852645ee2ce4027'/>
<id>807b692012ae921ac388cb2ea852645ee2ce4027</id>
<content type='text'>
Internally obstack used a backward word at a time copy.  This can be
an aliasing violation and likely slower than memcpy on most targets.
The code is a badly written memcpy with performance issues such as
the h-&gt;object_base indirection cannot be hoisted out of the loop.

On CHERI architecture this is needed for copying pointers correctly.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Internally obstack used a backward word at a time copy.  This can be
an aliasing violation and likely slower than memcpy on most targets.
The code is a badly written memcpy with performance issues such as
the h-&gt;object_base indirection cannot be hoisted out of the loop.

On CHERI architecture this is needed for copying pointers correctly.
</pre>
</div>
</content>
</entry>
<entry>
<title>cheri: malloc: Fix realloc to copy all relevant bytes</title>
<updated>2022-12-19T14:59:06+00:00</updated>
<author>
<name>Szabolcs Nagy</name>
<email>szabolcs.nagy@arm.com</email>
</author>
<published>2022-12-19T13:18:10+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/glibc.git/commit/?id=bbce0c75f35f55b9f5e43dd4fa01a82cc27bf020'/>
<id>bbce0c75f35f55b9f5e43dd4fa01a82cc27bf020</id>
<content type='text'>
New code in realloc that handles when new allocation is needed for
alignment reasons (for capability narrowing) used the wrong size in
memcpy (size was off by SIZE_SZ unless memory tagging was enabled)
and used wrongly tagged pointer for untagging the old memory.

Due to this bug realloc sometimes failed to copy tail bytes of an old
allocation to the new allocation when capability narrowing is enabled.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
New code in realloc that handles when new allocation is needed for
alignment reasons (for capability narrowing) used the wrong size in
memcpy (size was off by SIZE_SZ unless memory tagging was enabled)
and used wrongly tagged pointer for untagging the old memory.

Due to this bug realloc sometimes failed to copy tail bytes of an old
allocation to the new allocation when capability narrowing is enabled.
</pre>
</div>
</content>
</entry>
<entry>
<title>cheri: malloc: Set fixed mmap_threshold for capability narrowing</title>
<updated>2022-12-09T11:30:55+00:00</updated>
<author>
<name>Szabolcs Nagy</name>
<email>szabolcs.nagy@arm.com</email>
</author>
<published>2022-12-08T16:32:56+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/glibc.git/commit/?id=dc23cc80210799f8d8ab5b1ea2e00341e613a1a7'/>
<id>dc23cc80210799f8d8ab5b1ea2e00341e613a1a7</id>
<content type='text'>
Capability narrowing requires extra alignment for large allocations,
this can cause significant heap fragmentation so ensure large
allocations use a single mmap and unmaped on free. The fragmentation
is bug 14581.

This patch disables dynamic mmap threshold when cap_narrowing is
enabled and uses a threshold of 256 kbytes on morello (which means
at most 64 byte alignment requirement on the heap). The dynamic
threshold could quickly grow very big and stay there making the
fragmentation issue common.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Capability narrowing requires extra alignment for large allocations,
this can cause significant heap fragmentation so ensure large
allocations use a single mmap and unmaped on free. The fragmentation
is bug 14581.

This patch disables dynamic mmap threshold when cap_narrowing is
enabled and uses a threshold of 256 kbytes on morello (which means
at most 64 byte alignment requirement on the heap). The dynamic
threshold could quickly grow very big and stay there making the
fragmentation issue common.
</pre>
</div>
</content>
</entry>
<entry>
<title>cheri: malloc: Set __always_fail_morecore</title>
<updated>2022-12-08T17:41:46+00:00</updated>
<author>
<name>Szabolcs Nagy</name>
<email>szabolcs.nagy@arm.com</email>
</author>
<published>2022-12-05T13:31:54+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/glibc.git/commit/?id=da7a5b5f4df247726806ec7c5ce57d6bf4290a01'/>
<id>da7a5b5f4df247726806ec7c5ce57d6bf4290a01</id>
<content type='text'>
Morello linux does not support brk syscall, so fail early in the malloc
implementation instead of trying to use the syscall which always fails.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Morello linux does not support brk syscall, so fail early in the malloc
implementation instead of trying to use the syscall which always fails.
</pre>
</div>
</content>
</entry>
<entry>
<title>cheri: malloc: bump OBSTACK_INTERFACE_VERSION</title>
<updated>2022-12-08T17:27:31+00:00</updated>
<author>
<name>Szabolcs Nagy</name>
<email>szabolcs.nagy@arm.com</email>
</author>
<published>2022-12-01T16:58:55+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/glibc.git/commit/?id=1861652b2ee82eda7d466ae582d195b3b0dae116'/>
<id>1861652b2ee82eda7d466ae582d195b3b0dae116</id>
<content type='text'>
The obstack version should have been bumped after

  commit 2fd4de4b15a66f821057af90714145d2c034a609
  [BZ #321]

which changed a ptrdiff_t struct member into a union of ptrdiff_t and a
pointer and thus changed the ABI on targets where ptrdiff_t and pointer
have different size or alignment. This affects CHERI targets.

Old versions of obstack are used in the wild and conflict with the one
provided by glibc so at least on CHERI targets it has to be bumped.
On other targets we don't bump the version as it changes compile time
behaviour (the ABI remains backward compatible either way).
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The obstack version should have been bumped after

  commit 2fd4de4b15a66f821057af90714145d2c034a609
  [BZ #321]

which changed a ptrdiff_t struct member into a union of ptrdiff_t and a
pointer and thus changed the ABI on targets where ptrdiff_t and pointer
have different size or alignment. This affects CHERI targets.

Old versions of obstack are used in the wild and conflict with the one
provided by glibc so at least on CHERI targets it has to be bumped.
On other targets we don't bump the version as it changes compile time
behaviour (the ABI remains backward compatible either way).
</pre>
</div>
</content>
</entry>
<entry>
<title>cheri: malloc: disable capability narrowing on some tests</title>
<updated>2022-11-22T14:31:25+00:00</updated>
<author>
<name>Szabolcs Nagy</name>
<email>szabolcs.nagy@arm.com</email>
</author>
<published>2022-10-07T15:05:29+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/glibc.git/commit/?id=c38427f52d5386a25650ed982fa9a4af596a3f34'/>
<id>c38427f52d5386a25650ed982fa9a4af596a3f34</id>
<content type='text'>
malloc/tst-malloc-backtrace tests heap corruption.
malloc/tst-dynarray uses malloc_debug wrappers that access internals.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
malloc/tst-malloc-backtrace tests heap corruption.
malloc/tst-dynarray uses malloc_debug wrappers that access internals.
</pre>
</div>
</content>
</entry>
<entry>
<title>cheri: malloc: add tunable to turn narrowing off</title>
<updated>2022-11-22T14:31:25+00:00</updated>
<author>
<name>Szabolcs Nagy</name>
<email>szabolcs.nagy@arm.com</email>
</author>
<published>2022-10-06T11:00:39+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/glibc.git/commit/?id=de51f7328e62d59f20d7286899a99b35f746dfda'/>
<id>de51f7328e62d59f20d7286899a99b35f746dfda</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>cheri: malloc: Capability narrowing using internal lookup table</title>
<updated>2022-11-22T14:31:25+00:00</updated>
<author>
<name>Szabolcs Nagy</name>
<email>szabolcs.nagy@arm.com</email>
</author>
<published>2022-09-29T16:40:58+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/glibc.git/commit/?id=bd8fac4e2846e0621f87c675d7c609385a4d932d'/>
<id>bd8fac4e2846e0621f87c675d7c609385a4d932d</id>
<content type='text'>
Add more cap_ hooks to implement narrowing without depending on a
global capability covering the heap.  Either recording every
narrowed capability in a lookup table or recording every mapping
used for the heap are supported.  The morello implmentation uses
a lookup table for now.

The lookup table adds memory overhead, failure paths and locks.
Recording and removing entries from the lookup table must be done
carefully in realloc so on failure the old pointer is usable and
on success the old pointer is immediately reusable concurrently.
The locks require fork hooks so malloc works in multi-threaded
fork child.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Add more cap_ hooks to implement narrowing without depending on a
global capability covering the heap.  Either recording every
narrowed capability in a lookup table or recording every mapping
used for the heap are supported.  The morello implmentation uses
a lookup table for now.

The lookup table adds memory overhead, failure paths and locks.
Recording and removing entries from the lookup table must be done
carefully in realloc so on failure the old pointer is usable and
on success the old pointer is immediately reusable concurrently.
The locks require fork hooks so malloc works in multi-threaded
fork child.
</pre>
</div>
</content>
</entry>
<entry>
<title>cheri: malloc: Initial capability narrowing support</title>
<updated>2022-11-22T14:31:25+00:00</updated>
<author>
<name>Szabolcs Nagy</name>
<email>szabolcs.nagy@arm.com</email>
</author>
<published>2022-09-21T14:32:34+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/glibc.git/commit/?id=d7d9ee6edcb81380645de095a41f0f301c1bf5e1'/>
<id>d7d9ee6edcb81380645de095a41f0f301c1bf5e1</id>
<content type='text'>
Public interfaces return pointers with narrow bounds, this internally
requires bumping the size and alignment requirement of allocations so
the bounds are representible.

When pointers with narrow bounds need to be turned back to have wide
bounds (free, realloc), the pointer is rederived from DDC. (So this
patch relies on DDC to cover all heap memory with RW permission.)

Allocations above the mmap threshold waste memory for alignment and
realloc often falls back to the inefficient alloc, copy, free sequence
instead of mremap or other inplace solution.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Public interfaces return pointers with narrow bounds, this internally
requires bumping the size and alignment requirement of allocations so
the bounds are representible.

When pointers with narrow bounds need to be turned back to have wide
bounds (free, realloc), the pointer is rederived from DDC. (So this
patch relies on DDC to cover all heap memory with RW permission.)

Allocations above the mmap threshold waste memory for alignment and
realloc often falls back to the inefficient alloc, copy, free sequence
instead of mremap or other inplace solution.
</pre>
</div>
</content>
</entry>
</feed>
