-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ let | |
installPhase = '' | ||
mkdir -p $out/bin | ||
cp ${./setuid-wrapper.c} setuid-wrapper.c | ||
gcc -Wall -O2 -DWRAPPER_DIR=\"${wrapperDir}\" \ | ||
gcc -Wall -O2 -DWRAPPER_DIR=\"/run/setuid-wrapper-dirs\" \ | ||
setuid-wrapper.c -o $out/bin/setuid-wrapper | ||
''; | ||
}; | ||
|
@@ -102,11 +102,11 @@ in | |
source=/nix/var/nix/profiles/default/bin/${program} | ||
fi | ||
|
||
cp ${setuidWrapper}/bin/setuid-wrapper ${wrapperDir}/${program} | ||
echo -n "$source" > ${wrapperDir}/${program}.real | ||
chmod 0000 ${wrapperDir}/${program} # to prevent races | ||
chown ${owner}.${group} ${wrapperDir}/${program} | ||
chmod "u${if setuid then "+" else "-"}s,g${if setgid then "+" else "-"}s,${permissions}" ${wrapperDir}/${program} | ||
cp ${setuidWrapper}/bin/setuid-wrapper $wrapperDir/${program} | ||
echo -n "$source" > $wrapperDir/${program}.real | ||
chmod 0000 $wrapperDir/${program} # to prevent races | ||
chown ${owner}.${group} $wrapperDir/${program} | ||
chmod "u${if setuid then "+" else "-"}s,g${if setgid then "+" else "-"}s,${permissions}" $wrapperDir/${program} | ||
''; | ||
|
||
in stringAfter [ "users" ] | ||
|
@@ -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) | ||
|
||
${concatMapStrings makeSetuidWrapper setuidPrograms} | ||
|
||
if [ -L ${wrapperDir} ]; then | ||
# Atomically replace the symlink | ||
# See https://axialcorps.com/2013/07/03/atomically-replacing-files-and-directories/ | ||
old=$(readlink ${wrapperDir}) | ||
ln --symbolic --force --no-dereference $wrapperDir ${wrapperDir}-tmp | ||
mv --no-target-directory ${wrapperDir}-tmp ${wrapperDir} | ||
rm --force --recursive $old | ||
elif [ -d ${wrapperDir} ]; then | ||
# Compatibility with old state, just remove the folder and symlink | ||
rm -f ${wrapperDir}/* | ||
# if it happens to be a tmpfs | ||
umount ${wrapperDir} || true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we can rely on umout always being available, e.g. the activation script clears out the PATH. Should be:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 393e646 |
||
rm -d ${wrapperDir} | ||
ln -d --symbolic $wrapperDir ${wrapperDir} | ||
else | ||
# For initial setup | ||
ln --symbolic $wrapperDir ${wrapperDir} | ||
fi | ||
''; | ||
|
||
}; | ||
|
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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?