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

confd: fix double free of container hostname #716

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

rical
Copy link
Contributor

@rical rical commented Oct 15, 2024

Description

Fix a double free in the memory minefield surrounding container hostname provisioning. The hostnamefmt() function already does free() on success.

This caused all sorts of mayhem when working with multiple containers. However it mainly manifested itself by some containers not starting due to there activation script being polluted with gibberish name data. Your symptom might be different..

Example of polluted activation script

container --hostname foobar --net veth0k -r always \ create ^S@`M-}^G docker://ghcr.io/kernelkit/curios:edge

Side note

I haven't looked into it but is it really legit to free memory returned from the various lydx_ functions used here?
It seems to work as intended but it looks risky at a glance.

Checklist

Tick relevant boxes, this PR is-a or has-a:

  • Bugfix
    • Regression tests
    • ChangeLog updates (for next release)
  • Feature
    • YANG model change => revision updated?
    • Regression tests added?
    • ChangeLog updates (for next release)
    • Documentation added?
  • Test changes
    • Checked in changed Readme.adoc (make test-spec)
    • Added new test to group Readme.adoc and yaml file
  • Code style update (formatting, renaming)
  • Refactoring (please detail in commit messages)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

Fix a double free in the memory minefield surrounding container
hostname provisioning. The hostnamefmt() function already does free()
on success.

This caused all sorts of mayhem when working with multiple containers.
However it mainly manifested itself by some containers not starting
due to there activation script being polluted with gibberish
name data. Your symptom might be different..

Example of polluted activation script:
container --hostname foobar --net veth0k -r always \
  create ^S@`M-}^G docker://ghcr.io/kernelkit/curios:edge

Signed-off-by: Richard Alpe <[email protected]>
@troglobit
Copy link
Contributor

Ouch, nice catch! Although I cannot cannot reproduce in my limited setup, I agree that the current code needs work, and your fix is a good start, so let's merge this.

I'll submit a PR later that refactors int hostnamefmt(struct confd *confd, char **fmt) into int hostnamefmt(struct confd *confd, const char *fmt, char *buf, size_t len). Because we know that a hostname in Linux can only be 64 chars long, so a stack buffer for the return value is a much safer alternative.

@troglobit troglobit merged commit 08348c4 into kernelkit:main Oct 16, 2024
4 checks passed
@troglobit troglobit mentioned this pull request Oct 16, 2024
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants