mirror of
https://codeberg.org/guix/guix.git
synced 2025-10-02 02:15:12 +00:00
daemon: Address shortcoming in previous security fix for CVE-2024-27297.
This is a followup to8f4ffb3fae. Commit8f4ffb3faefell short in two ways: (1) it didn’t have any effet for fixed-output derivations performed in a chroot, which is the case for all of them except those using “builtin:download” and “builtin:git-download”, and (2) it did not preserve ownership when copying, leading to “suspicious ownership or permission […] rejecting this build output” errors. * nix/libstore/build.cc (DerivationGoal::buildDone): Account for ‘chrootRootDir’ when copying ‘drv.outputs’. * nix/libutil/util.cc (copyFileRecursively): Add ‘fchown’ and ‘fchownat’ calls to preserve file ownership; this is necessary for chrooted fixed-output derivation builds. * nix/libutil/util.hh: Update comment. Change-Id: Ib59f040e98fed59d1af81d724b874b592cbef156
This commit is contained in:
parent
fc1762fe38
commit
ff1251de0b
3 changed files with 14 additions and 8 deletions
|
|
@ -422,6 +422,7 @@ static void copyFileRecursively(int sourceroot, const Path &source,
|
|||
if (destinationFd == -1) throw SysError(format("opening `%1%'") % source);
|
||||
|
||||
copyFile(sourceFd, destinationFd);
|
||||
fchown(destinationFd, st.st_uid, st.st_gid);
|
||||
} else if (S_ISLNK(st.st_mode)) {
|
||||
char target[st.st_size + 1];
|
||||
ssize_t result = readlinkat(sourceroot, source.c_str(), target, st.st_size);
|
||||
|
|
@ -430,6 +431,8 @@ static void copyFileRecursively(int sourceroot, const Path &source,
|
|||
int err = symlinkat(target, destinationroot, destination.c_str());
|
||||
if (err != 0)
|
||||
throw SysError(format("creating symlink `%1%'") % destination);
|
||||
fchownat(destinationroot, destination.c_str(),
|
||||
st.st_uid, st.st_gid, AT_SYMLINK_NOFOLLOW);
|
||||
} else if (S_ISDIR(st.st_mode)) {
|
||||
int err = mkdirat(destinationroot, destination.c_str(), 0755);
|
||||
if (err != 0)
|
||||
|
|
@ -455,6 +458,7 @@ static void copyFileRecursively(int sourceroot, const Path &source,
|
|||
for (auto & i : readDirectory(sourceFd))
|
||||
copyFileRecursively((int)sourceFd, i.name, (int)destinationFd, i.name,
|
||||
deleteSource);
|
||||
fchown(destinationFd, st.st_uid, st.st_gid);
|
||||
} else throw Error(format("refusing to copy irregular file `%1%'") % source);
|
||||
|
||||
if (deleteSource)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue