Skip to content

varlink/pid1 fixes for systemd-oomd (addresses #20330) - #24919

Merged
keszybz merged 5 commits into
systemd:mainfrom
anitazha:varlinkserialize
Oct 17, 2022
Merged

keszybz merged 5 commits into
systemd:mainfrom
anitazha:varlinkserialize

Conversation

@anitazha

@anitazha anitazha commented Oct 5, 2022 •

Copy link
Copy Markdown
Member

Attempt to fix the 2 issues brought up in #20330.

The first few commits address the issue of serializing the varlink sockets across systemctl daemon-reexec boundaries.
The last commit adds a check so that only systemd-oomd can use SubscribeManagedOOMCGroups.

Comment thread src/shared/varlink.h Resolved

@keszybz keszybz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Partial review, because I ran out of time. Will continue later.

Comment thread src/shared/varlink.c Resolved
Comment thread src/core/core-varlink.c Resolved
Comment thread src/core/core-varlink.c Outdated
assert(ret_s);

if (m->varlink_server)
return 1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, what it the return convention, i.e. what is the difference between 0 and 1?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmmm I'm not sure. It looks like this all used to return 0 but was changed in 064a5c1. @daandemeyer is there a reason why we return both 0 and 1?

Comment thread src/core/manager-serialize.c Resolved
Comment thread src/core/core-varlink.c Resolved
@anitazha

anitazha commented Oct 7, 2022

Copy link
Copy Markdown
Member Author

Update according to review comments that seem unambiguous:

  • downgrade logs to debug in manager_setup_varlink_server()
  • skip deserialization if m->varlink_server exists
  • use free_and_strdup()

@anitazha

anitazha commented Oct 7, 2022 •

Copy link
Copy Markdown
Member Author

Latest update changes an assert to if to properly handle serialization in user managers

Comment thread src/shared/varlink.c Resolved
Comment thread src/core/core-varlink.c Resolved
@keszybz keszybz added the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Oct 7, 2022
Comment thread src/core/core-varlink.c Resolved
@anitazha

anitazha commented Oct 8, 2022

Copy link
Copy Markdown
Member Author

Changes:

  • fix commit message typo
  • use a command name check instead of username to avoid NSS lookup

@anitazha anitazha linked an issue Oct 8, 2022 that may be closed by this pull request
@bluca bluca added oomd and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Oct 8, 2022
Comment thread src/core/core-varlink.c Resolved
Comment thread src/shared/varlink.c Resolved
Comment thread src/core/manager-serialize.c Resolved
Comment thread src/shared/varlink.c Resolved
Comment thread src/core/core-varlink.c Resolved
@poettering poettering added the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Oct 10, 2022
@anitazha

Copy link
Copy Markdown
Member Author

I think I addressed all of the latest review comments:

  • updated from comm check to unit check
  • refactor varlink_server_attach_event() so we can attach socket events as they are deserialized
  • fix assert vs assert_return and naming nits

@bluca bluca removed the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Oct 11, 2022
@daandemeyer

Copy link
Copy Markdown
Collaborator

I'd still put the serialize/deserialize functions in varlink-internal.h or so to clearly indicate these are not intended for public distribution if we ever make varlink.h public

Comment thread src/shared/varlink.c Resolved
Comment thread src/core/core-varlink.c Resolved
Comment thread src/core/manager-serialize.c Resolved
Comment thread src/shared/varlink.c Resolved
@yuwata yuwata added the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Oct 11, 2022
@anitazha

Copy link
Copy Markdown
Member Author

Addressed the latest round of comments from Yu and split out the varlink serialize/deserialize into varlink-internal.h

@anitazha anitazha added varlink and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Oct 13, 2022

@keszybz keszybz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

Comment thread src/core/core-varlink.c Resolved
@keszybz keszybz added the 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 label Oct 13, 2022
Comment thread src/shared/varlink.c Resolved
Comment thread src/shared/varlink.c Resolved
Comment thread src/core/core-varlink.c Resolved
Comment thread src/core/core-varlink.c Resolved
Comment thread src/core/manager-serialize.c Resolved
Comment thread src/core/manager-serialize.c Resolved
Comment thread src/shared/varlink.c Resolved
Comment thread src/shared/varlink.c Resolved
Comment thread src/shared/varlink.h Resolved
Comment thread src/shared/varlink-internal.h Resolved
@yuwata yuwata added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed 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 labels Oct 13, 2022
Split out per-socket code into a separate function to use as part of
serialize/deserialize in the next commit.
@bluca bluca removed the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Oct 14, 2022
@anitazha

Copy link
Copy Markdown
Member Author

Addressed the latest round of comments from Yu and added a comment about why NSS is not used for the systemd-oomd unit check.

Comment thread src/shared/varlink-internal.h Resolved
Comment thread src/core/manager-serialize.c Resolved
@yuwata yuwata added the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Oct 14, 2022
Attempt to address
systemd#20330 (comment).

Summary of the comment: Unprivileged users can potentially cause a denial of
service during systemd-oomd unit subscriptions by spamming requests to
SubscribeManagedOOMCGroups. As systemd-oomd.service is the only unit that
should be accessing this method, add a check on the caller's unit name to deter
them from successfully using this method.
@anitazha

Copy link
Copy Markdown
Member Author

Fixed header and added comment.

@anitazha anitazha removed the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Oct 14, 2022
Comment thread src/core/core-varlink.c
if (!u)
return varlink_error(link, VARLINK_ERROR_PERMISSION_DENIED, NULL);

/* This is meant to be a deterrent and not actual security. The alternative is to check for the systemd-oom

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think that this comment is under-selling the protection provided here. Unit names are under control of root, and a unit name is not easy to fake. The attacker would need to move the PID into the systemd-oomd.service cgroup, which requires privileges again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

oomd fails during pid1 daemon-reexec

6 participants