@@ -31,6 +31,7 @@ import (
31
31
"github.com/opencontainers/runc/libcontainer/devices"
32
32
"github.com/opencontainers/runc/libcontainer/system"
33
33
"github.com/opencontainers/runc/libcontainer/utils"
34
+ "github.com/opencontainers/runc/libsysbox/syscont"
34
35
"github.com/opencontainers/runtime-spec/specs-go"
35
36
"github.com/opencontainers/selinux/go-selinux/label"
36
37
"github.com/sirupsen/logrus"
@@ -66,7 +67,7 @@ func prepareRootfs(pipe io.ReadWriter, iConfig *initConfig) (err error) {
66
67
return newSystemErrorWithCause (err , "effecting rootfs mount" )
67
68
}
68
69
69
- if err := doMounts (config , pipe ); err != nil {
70
+ if err := doMounts (config , pipe , false ); err != nil {
70
71
return newSystemErrorWithCause (err , "setting up rootfs mounts" )
71
72
}
72
73
@@ -219,6 +220,7 @@ func prepareBindDest(m *configs.Mount, absDestPath bool, config *configs.Config,
219
220
220
221
// update the mount with the correct dest after symlinks are resolved.
221
222
m .Destination = dest
223
+
222
224
if err = createIfNotExists (dest , m .BindSrcInfo .IsDir , config , pipe ); err != nil {
223
225
return err
224
226
}
@@ -501,7 +503,7 @@ func mountToRootfs(m *configs.Mount, config *configs.Config, enableCgroupns bool
501
503
}
502
504
}
503
505
504
- func doBindMounts (config * configs.Config , pipe io.ReadWriter ) error {
506
+ func doBindMounts (config * configs.Config , pipe io.ReadWriter , doSysboxfsOvermountsOnly bool ) error {
505
507
506
508
// sysbox-runc: the sys container's init process is in a dedicated
507
509
// user-ns, so it may not have search permission to the bind mount
@@ -527,6 +529,12 @@ func doBindMounts(config *configs.Config, pipe io.ReadWriter) error {
527
529
continue
528
530
}
529
531
532
+ isSysboxfsOvermount := isSysboxfsOvermount (m )
533
+ if doSysboxfsOvermountsOnly && ! isSysboxfsOvermount ||
534
+ ! doSysboxfsOvermountsOnly && isSysboxfsOvermount {
535
+ continue
536
+ }
537
+
530
538
// Determine if the current mount is dependent on a prior one.
531
539
mntDependsOnPrior := false
532
540
for _ , mr := range mntReqs {
@@ -584,6 +592,17 @@ func doBindMounts(config *configs.Config, pipe io.ReadWriter) error {
584
592
return nil
585
593
}
586
594
595
+ // isSysboxfsOvermount returns true if the given mount destination is under a
596
+ // sysbox-fs managed mountpoint.
597
+ func isSysboxfsOvermount (m * configs.Mount ) bool {
598
+ for _ , sysboxfsMount := range syscont .SysboxfsMounts {
599
+ if strings .HasPrefix (m .Destination , sysboxfsMount .Destination + "/" ) {
600
+ return true
601
+ }
602
+ }
603
+ return false
604
+ }
605
+
587
606
func chownMounts (config * configs.Config , pipe io.ReadWriter , chownList []string ) error {
588
607
chownReqs := []opReq {}
589
608
@@ -985,6 +1004,7 @@ func chroot() error {
985
1004
986
1005
// createIfNotExists creates a file or a directory only if it does not already exist.
987
1006
func createIfNotExists (path string , isDir bool , config * configs.Config , pipe io.ReadWriter ) error {
1007
+
988
1008
if _ , err := os .Stat (path ); err != nil {
989
1009
if os .IsNotExist (err ) {
990
1010
if isDir {
@@ -1179,13 +1199,22 @@ func doRootfsIDMapping(config *configs.Config, pipe io.ReadWriter) error {
1179
1199
return nil
1180
1200
}
1181
1201
1182
- // sysbox-runc: doMounts sets up all of the container's mounts as specified in the given config.
1183
- func doMounts (config * configs.Config , pipe io.ReadWriter ) error {
1202
+ // sysbox-runc: doMounts sets up the container's mounts as specified in the given config.
1203
+ // If sysboxfsOvermounts is true, then only mounts on top of sysbox-fs emulated paths are
1204
+ // mounted (e.g., mounts under /proc/sys/). Otherwise such mounts are skipped.
1205
+ func doMounts (config * configs.Config , pipe io.ReadWriter , doSysboxfsOvermountsOnly bool ) error {
1184
1206
1185
1207
chownList := []string {}
1186
1208
1187
1209
// Do non-bind mounts
1188
1210
for _ , m := range config .Mounts {
1211
+
1212
+ isSysboxfsOvermount := isSysboxfsOvermount (m )
1213
+ if doSysboxfsOvermountsOnly && ! isSysboxfsOvermount ||
1214
+ ! doSysboxfsOvermountsOnly && isSysboxfsOvermount {
1215
+ continue
1216
+ }
1217
+
1189
1218
if m .Device != "bind" {
1190
1219
if err := mountToRootfs (m , config , true , pipe ); err != nil {
1191
1220
return newSystemErrorWithCausef (err , "mounting %q to rootfs %q at %q" , m .Source , config .Rootfs , m .Destination )
@@ -1207,7 +1236,7 @@ func doMounts(config *configs.Config, pipe io.ReadWriter) error {
1207
1236
}
1208
1237
}
1209
1238
1210
- if err := doBindMounts (config , pipe ); err != nil {
1239
+ if err := doBindMounts (config , pipe , doSysboxfsOvermountsOnly ); err != nil {
1211
1240
return err
1212
1241
}
1213
1242
0 commit comments