@@ -878,6 +878,8 @@ func (c *containerMounter) mountSubmount(ctx context.Context, spec *specs.Spec,
878
878
return nil , fmt .Errorf ("creating mount point %q: %w" , mount .Destination , err )
879
879
}
880
880
881
+ // Avoid mounting on top of symlinks. The mount syscall on Linux always follows symlinks.
882
+ target .FollowFinalSymlink = true
881
883
if err := c .k .VFS ().ConnectMountAt (ctx , creds , mnt , target ); err != nil {
882
884
return nil , fmt .Errorf ("attaching %q to %q (type: %s): %w, opts: %v" ,
883
885
mount .Source , mount .Destination , mount .Type , err , opts )
@@ -1274,6 +1276,8 @@ func (c *containerMounter) mountSharedSubmount(ctx context.Context, conf *config
1274
1276
return nil , fmt .Errorf ("creating mount point %q: %w" , mntInfo .mount .Destination , err )
1275
1277
}
1276
1278
1279
+ // Avoid mounting on top of symlinks. The mount syscall on Linux always follows symlinks.
1280
+ target .FollowFinalSymlink = true
1277
1281
if err := c .k .VFS ().ConnectMountAt (ctx , creds , newMnt , target ); err != nil {
1278
1282
return nil , err
1279
1283
}
@@ -1296,9 +1300,10 @@ func (c *containerMounter) makeMountPoint(
1296
1300
defer root .DecRef (ctx )
1297
1301
1298
1302
target := & vfs.PathOperation {
1299
- Root : root ,
1300
- Start : root ,
1301
- Path : fspath .Parse (dest ),
1303
+ Root : root ,
1304
+ Start : root ,
1305
+ Path : fspath .Parse (dest ),
1306
+ FollowFinalSymlink : true ,
1302
1307
}
1303
1308
1304
1309
fs := c .k .VFS ()
@@ -1309,9 +1314,9 @@ func (c *containerMounter) makeMountPoint(
1309
1314
case err == nil :
1310
1315
if mode .IsDir () != rootMode .IsDir () {
1311
1316
if rootMode .IsDir () {
1312
- return fmt .Errorf ("mountpoint %q isn't a directory" , dest )
1317
+ return fmt .Errorf ("mountpoint %q isn't a directory, got mode %s " , dest , mode )
1313
1318
} else {
1314
- return fmt .Errorf ("mountpoint %q isn't not a file" , dest )
1319
+ return fmt .Errorf ("mountpoint %q isn't not a file, got mode %s " , dest , mode )
1315
1320
}
1316
1321
}
1317
1322
// Target already exists.
@@ -1322,6 +1327,8 @@ func (c *containerMounter) makeMountPoint(
1322
1327
return fmt .Errorf ("stat failed for %q during mountpoint creation: %w" , dest , err )
1323
1328
}
1324
1329
1330
+ // FollowFinalSymlink should be false to create new file or directory.
1331
+ target .FollowFinalSymlink = false
1325
1332
mkdirOpts := & vfs.MkdirOptions {Mode : 0755 , ForSyntheticMountpoint : true }
1326
1333
1327
1334
// Make sure the parent directory of target exists.
0 commit comments