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

Fixes #18124: atomically replace /var/setuid-wrappers/ #18186

Merged
merged 1 commit into from
Sep 1, 2016

Conversation

domenkozar
Copy link
Member

@domenkozar domenkozar commented Sep 1, 2016

Fixes #18124: atomically replace /var/setuid-wrappers/

Before this commit updating /var/setuid-wrappers/ folder introduced
a small window where NixOS activation scripts could be terminated
and resulted into empty /var/setuid-wrappers/ folder.

That's very unfortunate because one might lose sudo binary.

Instead we use two atomic operations mv and ln (as described in
https://axialcorps.com/2013/07/03/atomically-replacing-files-and-directories/)
to achieve atomicity.

Since /var/setuid-wrappers is not a directory anymore, tmpfs mountpoints
were removed in installation scripts and in boot process.

Tested:

- upgrade /var/setuid-wrappers/ from folder to a symlink
- make sure /run/setuid-wrappers-dirs/ legacy symlink is really deleted

@edolstra the good news the following protection works:

    /* Make sure that we are being executed from the right location,
       i.e., `wrapperDir'.  This is to prevent someone from
       creating hard link `X' from some other location, along with a
       false `X.real' file, to allow arbitrary programs from being
       executed setuid.  */
    assert ((strncmp(self, wrapperDir, strlen(wrapperDir)) == 0) &&
            (self[strlen(wrapperDir)] == '/'));

but we have to update it now, should we just hardcode /run/setuid-wrappers-dirs/?

cc @shlevy

@domenkozar domenkozar force-pushed the setuid-wrappers-atomic branch 2 times, most recently from ce81121 to cb3c1a7 Compare September 1, 2016 10:43
@domenkozar domenkozar added this to the 16.09 milestone Sep 1, 2016
@domenkozar domenkozar changed the title Fixes #18156: atomically replace /var/setuid-wrappers/ [WIP] Fixes #18156: atomically replace /var/setuid-wrappers/ Sep 1, 2016
@domenkozar domenkozar changed the title [WIP] Fixes #18156: atomically replace /var/setuid-wrappers/ [WIP] Fixes #18124: atomically replace /var/setuid-wrappers/ Sep 1, 2016
@domenkozar domenkozar force-pushed the setuid-wrappers-atomic branch from cb3c1a7 to e06bd0a Compare September 1, 2016 10:48
@shlevy
Copy link
Member

shlevy commented Sep 1, 2016

(for @edolstra: That's the "I've reviewed this" 👍 )

Before this commit updating /var/setuid-wrappers/ folder introduced
a small window where NixOS activation scripts could be terminated
and resulted into empty /var/setuid-wrappers/ folder.

That's very unfortunate because one might lose sudo binary.

Instead we use two atomic operations mv and ln (as described in
https://axialcorps.com/2013/07/03/atomically-replacing-files-and-directories/)
to achieve atomicity.

Since /var/setuid-wrappers is not a directory anymore, tmpfs mountpoints
were removed in installation scripts and in boot process.

Tested:

- upgrade /var/setuid-wrappers/ from folder to a symlink
- make sure /run/setuid-wrappers-dirs/ legacy symlink is really deleted
@domenkozar domenkozar force-pushed the setuid-wrappers-atomic branch from e06bd0a to 084ddc4 Compare September 1, 2016 18:57
@domenkozar domenkozar changed the title [WIP] Fixes #18124: atomically replace /var/setuid-wrappers/ Fixes #18124: atomically replace /var/setuid-wrappers/ Sep 1, 2016
@domenkozar
Copy link
Member Author

@edolstra I've hardcoded the new wrappers dir path, let me know if we should take another path.

@domenkozar domenkozar merged commit a6670c1 into NixOS:master Sep 1, 2016
@@ -115,9 +115,29 @@ in
# programs to be wrapped.
SETUID_PATH=${config.system.path}/bin:${config.system.path}/sbin

rm -f ${wrapperDir}/* # */
mkdir -p /run/setuid-wrapper-dirs
wrapperDir=$(mktemp --directory --tmpdir=/run/setuid-wrapper-dirs setuid-wrappers.XXXXXXXXXX)
Copy link
Contributor

Choose a reason for hiding this comment

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

This change breaks for me because mktemp sets permissions of drwx------ - any idea why this works for you?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe different defaults? There were some fixes yesterday, is this still an issue for you?

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

Successfully merging this pull request may close these issues.

3 participants