diff options
| -rw-r--r-- | nix/libstore/build.cc | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc index e77869fc3e4..0a4de96d51d 100644 --- a/nix/libstore/build.cc +++ b/nix/libstore/build.cc | |||
| @@ -1318,8 +1318,9 @@ MakeError(NotDeterministic, BuildError) | |||
| 1318 | /* Recursively make the file permissions of a path safe for exposure to | 1318 | /* Recursively make the file permissions of a path safe for exposure to |
| 1319 | arbitrary users, but without canonicalising its permissions, timestamp, and | 1319 | arbitrary users, but without canonicalising its permissions, timestamp, and |
| 1320 | user. Throw an exception if a file type that isn't explicitly known to be | 1320 | user. Throw an exception if a file type that isn't explicitly known to be |
| 1321 | safe is found. */ | 1321 | safe is found; when 'allowSpecialFiles' is true, pipes and sockets are |
| 1322 | static void secureFilePerms(Path path) | 1322 | allowed. */ |
| 1323 | static void secureFilePerms(Path path, bool allowSpecialFiles = false) | ||
| 1323 | { | 1324 | { |
| 1324 | struct stat st; | 1325 | struct stat st; |
| 1325 | if (lstat(path.c_str(), &st)) return; | 1326 | if (lstat(path.c_str(), &st)) return; |
| @@ -1330,7 +1331,7 @@ static void secureFilePerms(Path path) | |||
| 1330 | 1331 | ||
| 1331 | case S_IFDIR: | 1332 | case S_IFDIR: |
| 1332 | for (auto & i : readDirectory(path)) { | 1333 | for (auto & i : readDirectory(path)) { |
| 1333 | secureFilePerms(path + "/" + i.name); | 1334 | secureFilePerms(path + "/" + i.name, allowSpecialFiles); |
| 1334 | } | 1335 | } |
| 1335 | /* FALLTHROUGH */ | 1336 | /* FALLTHROUGH */ |
| 1336 | 1337 | ||
| @@ -1338,6 +1339,14 @@ static void secureFilePerms(Path path) | |||
| 1338 | chmod(path.c_str(), (st.st_mode & ~S_IFMT) & ~(S_ISUID | S_ISGID | S_IWOTH)); | 1339 | chmod(path.c_str(), (st.st_mode & ~S_IFMT) & ~(S_ISUID | S_ISGID | S_IWOTH)); |
| 1339 | break; | 1340 | break; |
| 1340 | 1341 | ||
| 1342 | case S_IFSOCK: | ||
| 1343 | case S_IFIFO: | ||
| 1344 | if (allowSpecialFiles) { | ||
| 1345 | chmod(path.c_str(), (st.st_mode & ~S_IFMT) & ~(S_ISUID | S_ISGID | S_IWOTH)); | ||
| 1346 | break; | ||
| 1347 | } | ||
| 1348 | /* FALLTHROUGH */ | ||
| 1349 | |||
| 1341 | default: | 1350 | default: |
| 1342 | throw Error(format("file `%1%' has an unsupported type") % path); | 1351 | throw Error(format("file `%1%' has an unsupported type") % path); |
| 1343 | } | 1352 | } |
| @@ -3401,8 +3410,9 @@ void DerivationGoal::deleteTmpDir(bool force) | |||
| 3401 | gid_t gid = settings.clientGid != 0 ? settings.clientGid : -1; | 3410 | gid_t gid = settings.clientGid != 0 ? settings.clientGid : -1; |
| 3402 | bool reown = false; | 3411 | bool reown = false; |
| 3403 | 3412 | ||
| 3404 | /* First remove setuid/setgid bits. */ | 3413 | /* First remove setuid/setgid bits. Allow sockets and pipes |
| 3405 | secureFilePerms(tmpDir); | 3414 | in the build directory. */ |
| 3415 | secureFilePerms(tmpDir, true); | ||
| 3406 | 3416 | ||
| 3407 | try { | 3417 | try { |
| 3408 | _chown(tmpDir, uid, gid); | 3418 | _chown(tmpDir, uid, gid); |
