Skip to content

ioctl socket fixes, sd-bus error updates, resolved error addition, PAM stub process priv fix#4299

Merged
evverx merged 8 commits intosystemd:masterfrom
poettering:variety
Oct 6, 2016
Merged

ioctl socket fixes, sd-bus error updates, resolved error addition, PAM stub process priv fix#4299
evverx merged 8 commits intosystemd:masterfrom
poettering:variety

Conversation

@poettering
Copy link
Member

Some minor fixes. @yuwata, @evverx please have a look!

@poettering poettering changed the title Variety ioctl socket fixes, sd-bus error updates, resolved error addition, PAM stub process priv fix Oct 6, 2016
* If this fails, ignore the error - but expect sd-pam threads
* to fail to exit normally */

if (setgroups(0, NULL) < 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed! (my PR predates the merging of the PR that introduced that)

if (setgroups(0, NULL) < 0)
log_warning_errno(errno, "Failed to setgroups() in sd-pam: %m");
if (setresgid(gid, gid, gid) < 0)
log_warning_errno(errno, "Failed to setresgid() in sd-pam: %m");
Copy link
Contributor

Choose a reason for hiding this comment

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

setresgid doesn't respect the SupplementaryGroups (enforce_groups respects)

Copy link
Member Author

Choose a reason for hiding this comment

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

what do you mean? I think it's totally fine if the auxiliary group list is empty in this case. We don't really care for the full cred initialiuation here. We only drop privs because we can here, because there's no need to stay root in the PAM stub.

Note that we don't even check whether the dropping of privs really worked, because it doesn't matter too much: if we remain privileged here, it's not a complete loss...

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, sorry, I mean there is a little difference. This doesn't really matter. Thanks!

@poettering
Copy link
Member Author

Will push an updated version shortly that, fixes the maybe_setgroups() thing.

Thanks for the reviews!

@poettering
Copy link
Member Author

OK, i force pushed a new version, that calls maye_setgroups() instead of setgroups() now, as suggested by @evverx.

I also added another new commit that rewokrs maybe_setgroups() a bit, and drops its caching. It also normalizes the error handling of it, to match the way we usually do it in our tree.

@poettering
Copy link
Member Author

@giuseppe, @zonque, @evverx, @yuwata please have a look at this new version!

@giuseppe
Copy link
Contributor

giuseppe commented Oct 6, 2016

@poettering LGTM, and I've learned a few more tricks about systemd hacking looking at it.

…tls on

As suggested here:

systemd#4296 (comment)

Let's try AF_INET first as socket, but let's fall back to AF_NETLINK, so that
we can use a protocol-independent socket here if possible. This has the benefit
that our code will still work even if AF_INET/AF_INET6 is made unavailable (for
exmple via seccomp), at least on current kernels.
These were forgotten, let's add some useful mappings for all errors we define.
Add this new error code (documented in RFC7873) to our list of known errors.
We generate these, hence we should also add errno translations for them.
In the process execution code of PID 1, before
096424d the GID settings where changed before
invoking PAM, and the UID settings after. After the change both changes are
made after the PAM session hooks are run. When invoking PAM we fork once, and
leave a stub process around which will invoke the PAM session end hooks when
the session goes away. This code previously was dropping the remaining privs
(which were precisely the UID). Fix this code to do this correctly again, by
really dropping them else (i.e. the GID as well).

While we are at it, also fix error logging of this code.

Fixes: systemd#4238
gcc at some optimization levels thinks thes variables were used without
initialization. it's wrong, but let's make the message go anyway.
Let's drop the caching of the setgroups /proc field for now. While there's a
strict regime in place when it changes states, let's better not cache it since
we cannot really be sure we follow that regime correctly.

More importantly however, this is not in performance sensitive code, and
there's no indication the cache is really beneficial, hence let's drop the
caching and make things a bit simpler.

Also, while we are at it, rework the error handling a bit, and always return
negative errno-style error codes, following our usual coding style. This has
the benefit that we can sensible hanld read_one_line_file() errors, without
having to updat errno explicitly.
@poettering
Copy link
Member Author

force pushed new version with the kernel version comment fix as suggested by @evverx applied. please have a look

@evverx evverx merged commit 36264e0 into systemd:master Oct 6, 2016
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.

4 participants