@@ -48,12 +48,13 @@ func init() {
48
48
type runUsingChrootExecSubprocOptions struct {
49
49
Spec * specs.Spec
50
50
BundlePath string
51
+ NoPivot bool
51
52
}
52
53
53
54
// RunUsingChroot runs a chrooted process, using some of the settings from the
54
55
// passed-in spec, and using the specified bundlePath to hold temporary files,
55
56
// directories, and mountpoints.
56
- func RunUsingChroot (spec * specs.Spec , bundlePath , homeDir string , stdin io.Reader , stdout , stderr io.Writer ) (err error ) {
57
+ func RunUsingChroot (spec * specs.Spec , bundlePath , homeDir string , stdin io.Reader , stdout , stderr io.Writer , noPivot bool ) (err error ) {
57
58
var confwg sync.WaitGroup
58
59
var homeFound bool
59
60
for _ , env := range spec .Process .Env {
@@ -97,6 +98,7 @@ func RunUsingChroot(spec *specs.Spec, bundlePath, homeDir string, stdin io.Reade
97
98
config , conferr := json .Marshal (runUsingChrootSubprocOptions {
98
99
Spec : spec ,
99
100
BundlePath : bundlePath ,
101
+ NoPivot : noPivot ,
100
102
})
101
103
if conferr != nil {
102
104
return fmt .Errorf ("encoding configuration for %q: %w" , runUsingChrootCommand , conferr )
@@ -196,6 +198,7 @@ func runUsingChrootMain() {
196
198
fmt .Fprintf (os .Stderr , "invalid options spec in runUsingChrootMain\n " )
197
199
os .Exit (1 )
198
200
}
201
+ noPivot := options .NoPivot
199
202
200
203
// Prepare to shuttle stdio back and forth.
201
204
rootUID32 , rootGID32 , err := util .GetHostRootIDs (options .Spec )
@@ -442,7 +445,7 @@ func runUsingChrootMain() {
442
445
}()
443
446
444
447
// Set up mounts and namespaces, and run the parent subprocess.
445
- status , err := runUsingChroot (options .Spec , options .BundlePath , ctty , stdin , stdout , stderr , closeOnceRunning )
448
+ status , err := runUsingChroot (options .Spec , options .BundlePath , ctty , stdin , stdout , stderr , noPivot , closeOnceRunning )
446
449
if err != nil {
447
450
fmt .Fprintf (os .Stderr , "error running subprocess: %v\n " , err )
448
451
os .Exit (1 )
@@ -463,7 +466,7 @@ func runUsingChrootMain() {
463
466
// runUsingChroot, still in the grandparent process, sets up various bind
464
467
// mounts and then runs the parent process in its own user namespace with the
465
468
// necessary ID mappings.
466
- func runUsingChroot (spec * specs.Spec , bundlePath string , ctty * os.File , stdin io.Reader , stdout , stderr io.Writer , closeOnceRunning []* os.File ) (wstatus unix.WaitStatus , err error ) {
469
+ func runUsingChroot (spec * specs.Spec , bundlePath string , ctty * os.File , stdin io.Reader , stdout , stderr io.Writer , noPivot bool , closeOnceRunning []* os.File ) (wstatus unix.WaitStatus , err error ) {
467
470
var confwg sync.WaitGroup
468
471
469
472
// Create a new mount namespace for ourselves and bind mount everything to a new location.
@@ -496,6 +499,7 @@ func runUsingChroot(spec *specs.Spec, bundlePath string, ctty *os.File, stdin io
496
499
config , conferr := json .Marshal (runUsingChrootExecSubprocOptions {
497
500
Spec : spec ,
498
501
BundlePath : bundlePath ,
502
+ NoPivot : noPivot ,
499
503
})
500
504
if conferr != nil {
501
505
fmt .Fprintf (os .Stderr , "error re-encoding configuration for %q\n " , runUsingChrootExecCommand )
@@ -619,8 +623,10 @@ func runUsingChrootExecMain() {
619
623
// Try to chroot into the root. Do this before we potentially
620
624
// block the syscall via the seccomp profile. Allow the
621
625
// platform to override this - on FreeBSD, we use a simple
622
- // jail to set the hostname in the container
626
+ // jail to set the hostname in the container, and on Linux
627
+ // we attempt to pivot_root.
623
628
if err := createPlatformContainer (options ); err != nil {
629
+ logrus .Debugf ("createPlatformContainer: %v" , err )
624
630
var oldst , newst unix.Stat_t
625
631
if err := unix .Stat (options .Spec .Root .Path , & oldst ); err != nil {
626
632
fmt .Fprintf (os .Stderr , "error stat()ing intended root directory %q: %v\n " , options .Spec .Root .Path , err )
0 commit comments