Skip to content

systemctl: add possibility to skip the chroot check#4374

Merged
keszybz merged 1 commit intosystemd:masterfrom
lnykryn:systemctl_allow_chroot
Oct 15, 2016
Merged

systemctl: add possibility to skip the chroot check#4374
keszybz merged 1 commit intosystemd:masterfrom
lnykryn:systemctl_allow_chroot

Conversation

@lnykryn
Copy link
Member

@lnykryn lnykryn commented Oct 14, 2016

@lnykryn lnykryn force-pushed the systemctl_allow_chroot branch from ce6188c to c8343c8 Compare October 14, 2016 09:14
const char *e;
int r;

e = getenv("SYSTEMCTL_ALLOW_CHROOT");
Copy link
Member

Choose a reason for hiding this comment

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

please use getenv_bool() for this, it makes this call a bit simpler...

goto finish;

if (arg_action != ACTION_SYSTEMCTL && running_in_chroot() > 0) {
if (arg_action != ACTION_SYSTEMCTL && running_in_chroot() > 0 && !arg_allow_chroot) {
Copy link
Member

Choose a reason for hiding this comment

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

there are a couple of more cases where we check for chroots in systemctl.c, what about those? There's also the VERB_NOCHROOT logic used all over the place, what about that?

Maybe the env var check should be added to running_in_chroot() itself, so that it applies everywhere? (and then probably be renamed to $SYSTEMD_IGNORE_CHROOT or so?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it probably make sense, I will rewrite that.

@poettering poettering added systemctl reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Oct 14, 2016
@lnykryn lnykryn force-pushed the systemctl_allow_chroot branch 2 times, most recently from 989494d to 8e45a05 Compare October 14, 2016 11:51
@lnykryn lnykryn removed the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Oct 14, 2016
@lnykryn
Copy link
Member Author

lnykryn commented Oct 14, 2016

I have force pushed the branch with the SYSTEMD_IGNORE_CHROOT stuff. I am just not sure if getenv_bool should not use secure_getenv instead.

@lnykryn lnykryn force-pushed the systemctl_allow_chroot branch from 8e45a05 to dbc827a Compare October 14, 2016 11:53
@keszybz
Copy link
Member

keszybz commented Oct 15, 2016

I am just not sure if getenv_bool should not use secure_getenv instead.

secure_getenv is only useful for library code. Quoting the man page:
The secure_getenv() function is intended for use in general-purpose libraries to
avoid vulnerabilities that could occur if set-user-ID or set-group-ID programs
accidentally trusted the environment.

LGTM.

@keszybz keszybz merged commit 08a28ee into systemd:master Oct 15, 2016
@lnykryn
Copy link
Member Author

lnykryn commented Oct 16, 2016

But we are using secure_getenv i environment_parse_log functions, which looks to me as a similar case now,

keszybz added a commit to keszybz/systemd that referenced this pull request Oct 16, 2016
secure_getenv(3) says:

   The secure_getenv() function is intended for use in general-purpose
   libraries to avoid vulnerabilities that could occur if set-user-ID or
   set-group-ID programs accidentally trusted the environment.

log_parse_environment is only used internally in our daemons and is not
exported as a library function, or called by any of the library functions.
And it should not be: it uses systemd specific variable names.

So using secure_getenv() is not necessary. Our daemons are not written to be
used suid, and we should not pretend that anything like that is supported.

While at it, improve the error messages to mention what we were trying to
parse.

Follow-up for systemd#4374.
@poettering
Copy link
Member

Hmm, the getenv() vs. secure_getenv() thing is a pretty good question. So far I mostly treated src/shared and in particular src/basic as library code, as it is exposed indirectly (at least partially) in libsystemd.so, hence I ended up using secure_getenv() for most of that code, except for some obvious cases. I have the suspicion that secure_getenv_bool() probably wouldn't be the worst of the ideas...

That said, I figure in this specific case it really doesn't matter, dunno if we should really bother...

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.

3 participants