Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

malloc_usable_size() tweaks #19653

Merged
merged 3 commits into from
May 19, 2021
Merged

Conversation

poettering
Copy link
Member

Fixes: #19203

@github-actions github-actions bot added busctl journal journal-remote network portable Anything to do with systemd-portable and portablectl and portables resolve systemctl udev labels May 18, 2021
@yuwata
Copy link
Member

yuwata commented May 19, 2021

../../../../src/journal/fuzz-journald.c: In function ‘dummy_server_init’:
../../../../src/journal/fuzz-journald.c:25:18: error: ‘Server’ has no member named ‘buffer_size’
   25 |                 s->buffer_size = size + 1;
      |                  ^~

@yuwata yuwata added the ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR label May 19, 2021
@poettering poettering removed the ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR label May 19, 2021
@poettering poettering force-pushed the greedy-realloc-more branch 2 times, most recently from 9d16390 to 900e170 Compare May 19, 2021 14:23
Copy link
Member

@yuwata yuwata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but one minor comment.

src/test/test-alloc-util.c Outdated Show resolved Hide resolved
It's a wrapper around malloc_usable_size() that is supposed to be
compatible with _FORTIFY_SOURCES=1, by taking the
__builtin_object_size() data into account, the same way as the
_FORTIFY_SOURCES=1 logic does.

Fixes: systemd#19203
This is a wrapper around malloc_usable_size() but is typesafe, and
divides by the element size.

A test it is also added ensuring what it does it does correcly.
…le_size()

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.)
@poettering
Copy link
Member Author

fixed the issue @yuwata found. upgrading green label

@poettering poettering added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed good-to-merge/with-minor-suggestions labels May 19, 2021
@poettering poettering merged commit ed056c5 into systemd:main May 19, 2021
yuwata added a commit to yuwata/systemd that referenced this pull request May 20, 2021
This fixes a conflict between systemd#19555 and systemd#19653.
poettering pushed a commit that referenced this pull request May 20, 2021
This fixes a conflict between #19555 and #19653.
dakr pushed a commit to dakr/systemd that referenced this pull request Jun 14, 2021
This fixes a conflict between systemd#19555 and systemd#19653.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
busctl good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed journal journal-remote network portable Anything to do with systemd-portable and portablectl and portables resolve systemctl udev util-lib
Development

Successfully merging this pull request may close these issues.

cryptenroll --recovery-key crashes
2 participants