<feed xmlns='http://www.w3.org/2005/Atom'>
<title>delta/systemd.git/src/basic/alloc-util.c, branch main</title>
<subtitle>github.com: systemd/systemd.git
</subtitle>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/systemd.git/'/>
<entry>
<title>Use dummy allocator to make accesses defined as per standard</title>
<updated>2022-12-14T16:49:47+00:00</updated>
<author>
<name>Siddhesh Poyarekar</name>
<email>siddhesh@gotplt.org</email>
</author>
<published>2022-12-13T21:54:36+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/systemd.git/commit/?id=7929e180aa47a2692ad4f053afac2857d7198758'/>
<id>7929e180aa47a2692ad4f053afac2857d7198758</id>
<content type='text'>
systemd uses malloc_usable_size() everywhere to use memory blocks
obtained through malloc, but that is abuse since the
malloc_usable_size() interface isn't meant for this kind of use, it is
for diagnostics only.  This is also why systemd behaviour is flaky when
built with _FORTIFY_SOURCE.

One way to make this more standard (and hence safer) is to, at every
malloc_usable_size() call, also 'reallocate' the block so that the
compiler can see the larger size.  This is done through a dummy
reallocator whose only purpose is to tell the compiler about the larger
usable size, it doesn't do any actual reallocation.

Florian Weimer pointed out that this doesn't solve the problem of an
allocator potentially growing usable size at will, which will break the
implicit assumption in systemd use that the value returned remains
constant as long as the object is valid.  The safest way to fix that is
for systemd to step away from using malloc_usable_size() like this.

Resolves #22801.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
systemd uses malloc_usable_size() everywhere to use memory blocks
obtained through malloc, but that is abuse since the
malloc_usable_size() interface isn't meant for this kind of use, it is
for diagnostics only.  This is also why systemd behaviour is flaky when
built with _FORTIFY_SOURCE.

One way to make this more standard (and hence safer) is to, at every
malloc_usable_size() call, also 'reallocate' the block so that the
compiler can see the larger size.  This is done through a dummy
reallocator whose only purpose is to tell the compiler about the larger
usable size, it doesn't do any actual reallocation.

Florian Weimer pointed out that this doesn't solve the problem of an
allocator potentially growing usable size at will, which will break the
implicit assumption in systemd use that the value returned remains
constant as long as the object is valid.  The safest way to fix that is
for systemd to step away from using malloc_usable_size() like this.

Resolves #22801.
</pre>
</div>
</content>
</entry>
<entry>
<title>Merge pull request #19662 from yuwata/memdup</title>
<updated>2021-05-19T21:24:55+00:00</updated>
<author>
<name>Lennart Poettering</name>
<email>lennart@poettering.net</email>
</author>
<published>2021-05-19T21:24:55+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/systemd.git/commit/?id=2adcf6f4f7d1f74b02553d7128f73fcd2886fa55'/>
<id>2adcf6f4f7d1f74b02553d7128f73fcd2886fa55</id>
<content type='text'>
util: make memdup() or friends safer</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
util: make memdup() or friends safer</pre>
</div>
</content>
</entry>
<entry>
<title>alloc-util: simplify GREEDY_REALLOC() logic by relying on malloc_usable_size()</title>
<updated>2021-05-19T14:42:37+00:00</updated>
<author>
<name>Lennart Poettering</name>
<email>lennart@poettering.net</email>
</author>
<published>2021-05-18T21:01:32+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/systemd.git/commit/?id=319a4f4bc46b230fc660321e99aaac1bc449deea'/>
<id>319a4f4bc46b230fc660321e99aaac1bc449deea</id>
<content type='text'>
We recently started making more use of malloc_usable_size() and rely on
it (see the string_erase() story). Given that we don't really support
sytems where malloc_usable_size() cannot be trusted beyond statistics
anyway, let's go fully in and rework GREEDY_REALLOC() on top of it:
instead of passing around and maintaining the currenly allocated size
everywhere, let's just derive it automatically from
malloc_usable_size().

I am mostly after this for the simplicity this brings. It also brings
minor efficiency improvements I guess, but things become so much nicer
to look at if we can avoid these allocation size variables everywhere.

Note that the malloc_usable_size() man page says relying on it wasn't
"good programming practice", but I think it does this for reasons that
don't apply here: the greedy realloc logic specifically doesn't rely on
the returned extra size, beyond the fact that it is equal or larger than
what was requested.

(This commit was supposed to be a quick patch btw, but apparently we use
the greedy realloc stuff quite a bit across the codebase, so this ends
up touching *a*lot* of code.)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We recently started making more use of malloc_usable_size() and rely on
it (see the string_erase() story). Given that we don't really support
sytems where malloc_usable_size() cannot be trusted beyond statistics
anyway, let's go fully in and rework GREEDY_REALLOC() on top of it:
instead of passing around and maintaining the currenly allocated size
everywhere, let's just derive it automatically from
malloc_usable_size().

I am mostly after this for the simplicity this brings. It also brings
minor efficiency improvements I guess, but things become so much nicer
to look at if we can avoid these allocation size variables everywhere.

Note that the malloc_usable_size() man page says relying on it wasn't
"good programming practice", but I think it does this for reasons that
don't apply here: the greedy realloc logic specifically doesn't rely on
the returned extra size, beyond the fact that it is equal or larger than
what was requested.

(This commit was supposed to be a quick patch btw, but apparently we use
the greedy realloc stuff quite a bit across the codebase, so this ends
up touching *a*lot* of code.)
</pre>
</div>
</content>
</entry>
<entry>
<title>alloc-util: use memcpy_safe() in memdup() or friends</title>
<updated>2021-05-19T12:22:23+00:00</updated>
<author>
<name>Yu Watanabe</name>
<email>watanabe.yu+github@gmail.com</email>
</author>
<published>2021-05-19T12:21:28+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/systemd.git/commit/?id=550721c2e307f4104a470c27271ab6580b2e5444'/>
<id>550721c2e307f4104a470c27271ab6580b2e5444</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>license: LGPL-2.1+ -&gt; LGPL-2.1-or-later</title>
<updated>2020-11-09T04:23:58+00:00</updated>
<author>
<name>Yu Watanabe</name>
<email>watanabe.yu+github@gmail.com</email>
</author>
<published>2020-11-09T04:23:58+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/systemd.git/commit/?id=db9ecf050165fd1033c6f81485917e229c4be537'/>
<id>db9ecf050165fd1033c6f81485917e229c4be537</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>tree-wide: various code-formatting improvements</title>
<updated>2019-09-22T05:17:27+00:00</updated>
<author>
<name>Frantisek Sumsal</name>
<email>frantisek@sumsal.cz</email>
</author>
<published>2019-09-21T14:01:14+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/systemd.git/commit/?id=38288f0bb843bf4c0ad7aacea5c81254b2d7d00b'/>
<id>38288f0bb843bf4c0ad7aacea5c81254b2d7d00b</id>
<content type='text'>
Reported/found by Coccinelle
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Reported/found by Coccinelle
</pre>
</div>
</content>
</entry>
<entry>
<title>alloc-util: reintroduce malloc_usable_size() into greedy_realloc()</title>
<updated>2019-05-02T12:53:40+00:00</updated>
<author>
<name>Lennart Poettering</name>
<email>lennart@poettering.net</email>
</author>
<published>2019-04-30T08:13:57+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/systemd.git/commit/?id=e59054270c6e37fd08fdd5d0231edd17c7f7495a'/>
<id>e59054270c6e37fd08fdd5d0231edd17c7f7495a</id>
<content type='text'>
This is another attempt at d4b604baeadbb2498e4f2c3e260260eed210f5d6 and #12438

Instead of blindly using the extra allocated space, let's do so only
after telling libc about it, via a second realloc(). The second
realloc() should be quick, since it never has to copy memory around.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This is another attempt at d4b604baeadbb2498e4f2c3e260260eed210f5d6 and #12438

Instead of blindly using the extra allocated space, let's do so only
after telling libc about it, via a second realloc(). The second
realloc() should be quick, since it never has to copy memory around.
</pre>
</div>
</content>
</entry>
<entry>
<title>alloc-util: don't use malloc_usable_size() to determine allocated size</title>
<updated>2019-04-30T06:20:59+00:00</updated>
<author>
<name>Aaron Barany</name>
<email>aaron.barany@here.com</email>
</author>
<published>2019-04-29T22:00:30+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/systemd.git/commit/?id=fcc72fd0f103c95810f0335684d0bf6f6ed6481b'/>
<id>fcc72fd0f103c95810f0335684d0bf6f6ed6481b</id>
<content type='text'>
This reverts commit d4b604baeadbb2498e4f2c3e260260eed210f5d6.

When realloc() is called, the extra memory between the originally
requested size and the end of malloc_usable_size() isn't copied. (at
least with the version of glibc that currently ships on Arch Linux)
As a result, some elements get lost and use uninitialized memory, most
commonly 0, and can lead to crashes.

fixes #12384
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This reverts commit d4b604baeadbb2498e4f2c3e260260eed210f5d6.

When realloc() is called, the extra memory between the originally
requested size and the end of malloc_usable_size() isn't copied. (at
least with the version of glibc that currently ships on Arch Linux)
As a result, some elements get lost and use uninitialized memory, most
commonly 0, and can lead to crashes.

fixes #12384
</pre>
</div>
</content>
</entry>
<entry>
<title>alloc-util: use malloc_usable_size() to determine allocated size</title>
<updated>2019-03-20T09:48:33+00:00</updated>
<author>
<name>Lennart Poettering</name>
<email>lennart@poettering.net</email>
</author>
<published>2019-03-20T09:31:38+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/systemd.git/commit/?id=d4b604baeadbb2498e4f2c3e260260eed210f5d6'/>
<id>d4b604baeadbb2498e4f2c3e260260eed210f5d6</id>
<content type='text'>
It's a glibc-specific API, but supported on FreeBSD and musl too at
least, hence fairly common. This way we can reduce our calls to
realloc() as much as possible.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
It's a glibc-specific API, but supported on FreeBSD and musl too at
least, hence fairly common. This way we can reduce our calls to
realloc() as much as possible.
</pre>
</div>
</content>
</entry>
<entry>
<title>alloc-util: add extra overflow checks to GREEDY_REALLOC()</title>
<updated>2019-03-20T09:48:33+00:00</updated>
<author>
<name>Lennart Poettering</name>
<email>lennart@poettering.net</email>
</author>
<published>2019-03-20T09:31:13+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/systemd.git/commit/?id=23964f7faf86df7fd297dc5b0a9f1dfb03a0eb56'/>
<id>23964f7faf86df7fd297dc5b0a9f1dfb03a0eb56</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
</feed>
