Skip to content

Commit d7fc293

Browse files
Merge pull request NixOS#14534 from NixOS/backport-14531-to-2.32-maintenance
[Backport 2.32-maintenance] Restore isAllowed check in ChrootLinuxDerivationBuilder
2 parents 5b8c24f + 46a43de commit d7fc293

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/libstore/include/nix/store/restricted-store.hh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,21 @@ struct RestrictionContext
5252
* Add 'path' to the set of paths that may be referenced by the
5353
* outputs, and make it appear in the sandbox.
5454
*/
55-
virtual void addDependency(const StorePath & path) = 0;
55+
void addDependency(const StorePath & path)
56+
{
57+
if (isAllowed(path))
58+
return;
59+
addDependencyImpl(path);
60+
}
61+
62+
protected:
63+
64+
/**
65+
* This is the underlying implementation to be defined. The caller
66+
* will ensure that this is only called on newly added dependencies,
67+
* and that idempotent calls are a no-op.
68+
*/
69+
virtual void addDependencyImpl(const StorePath & path) = 0;
5670
};
5771

5872
/**

src/libstore/unix/build/derivation-builder.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class DerivationBuilderImpl : public DerivationBuilder, public DerivationBuilder
325325

326326
protected:
327327

328-
void addDependency(const StorePath & path) override;
328+
void addDependencyImpl(const StorePath & path) override;
329329

330330
/**
331331
* Make a file owned by the builder.
@@ -1181,11 +1181,8 @@ void DerivationBuilderImpl::stopDaemon()
11811181
daemonSocket.close();
11821182
}
11831183

1184-
void DerivationBuilderImpl::addDependency(const StorePath & path)
1184+
void DerivationBuilderImpl::addDependencyImpl(const StorePath & path)
11851185
{
1186-
if (isAllowed(path))
1187-
return;
1188-
11891186
addedPaths.insert(path);
11901187
}
11911188

src/libstore/unix/build/linux-derivation-builder.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,11 @@ struct ChrootLinuxDerivationBuilder : ChrootDerivationBuilder, LinuxDerivationBu
703703
DerivationBuilderImpl::killSandbox(getStats);
704704
}
705705

706-
void addDependency(const StorePath & path) override
706+
void addDependencyImpl(const StorePath & path) override
707707
{
708+
if (isAllowed(path))
709+
return;
710+
708711
auto [source, target] = ChrootDerivationBuilder::addDependencyPrep(path);
709712

710713
/* Bind-mount the path into the sandbox. This requires

0 commit comments

Comments
 (0)