mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Fix failure to mount volume that sandbox process has no access
Boot loader tries to stat mount to determine whether it's a file or not. This may file if the sandbox process doesn't have access to the file. Instead, add overlay on top of file, which is better anyway since we don't want to propagate changes to the host. PiperOrigin-RevId: 200411261 Change-Id: I14222410e8bc00ed037b779a1883d503843ffebb
This commit is contained in:
committed by
Shentubot
parent
686093669e
commit
717f2501c9
@@ -103,6 +103,28 @@ func NewOverlayRoot(ctx context.Context, upper *Inode, lower *Inode, flags Mount
|
||||
return newOverlayInode(ctx, overlay, msrc), nil
|
||||
}
|
||||
|
||||
// NewOverlayRootFile produces the root of an overlay that points to a file.
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// - lower must be non-nil.
|
||||
// - lower should not expose character devices, pipes, or sockets, because
|
||||
// copying up these types of files is not supported. Neither it can be a dir.
|
||||
// - lower must not require that file objects be revalidated.
|
||||
// - lower must not have dynamic file/directory content.
|
||||
func NewOverlayRootFile(ctx context.Context, upperMS *MountSource, lower *Inode, flags MountSourceFlags) (*Inode, error) {
|
||||
if IsRegular(lower.StableAttr) {
|
||||
return nil, fmt.Errorf("lower Inode is not a regular file")
|
||||
}
|
||||
msrc := newOverlayMountSource(upperMS, lower.MountSource, flags)
|
||||
overlay, err := newOverlayEntry(ctx, nil, lower, true)
|
||||
if err != nil {
|
||||
msrc.DecRef()
|
||||
return nil, err
|
||||
}
|
||||
return newOverlayInode(ctx, overlay, msrc), nil
|
||||
}
|
||||
|
||||
// newOverlayInode creates a new Inode for an overlay.
|
||||
func newOverlayInode(ctx context.Context, o *overlayEntry, msrc *MountSource) *Inode {
|
||||
var inode *Inode
|
||||
|
||||
+9
-7
@@ -16,7 +16,6 @@ package boot
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -209,6 +208,13 @@ func addOverlay(ctx context.Context, conf *Config, lower *fs.Inode, name string,
|
||||
lowerFlags.ReadOnly = false
|
||||
|
||||
tmpFS := mustFindFilesystem("tmpfs")
|
||||
if !fs.IsDir(lower.StableAttr) {
|
||||
// Create overlay on top of mount file, e.g. /etc/hostname.
|
||||
msrc := fs.NewCachingMountSource(tmpFS, lowerFlags)
|
||||
return fs.NewOverlayRootFile(ctx, msrc, lower, lowerFlags)
|
||||
}
|
||||
|
||||
// Create overlay on top of mount dir.
|
||||
upper, err := tmpFS.Mount(ctx, name+"-upper", lowerFlags, "")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create tmpfs overlay: %v", err)
|
||||
@@ -248,13 +254,9 @@ func mountSubmount(ctx context.Context, spec *specs.Spec, conf *Config, mns *fs.
|
||||
default:
|
||||
return fmt.Errorf("invalid file access type: %v", conf.FileAccess)
|
||||
}
|
||||
// If configured, add overlay to all writable mounts.
|
||||
useOverlay = conf.Overlay && !mountFlags(m.Options).ReadOnly
|
||||
|
||||
fi, err := os.Stat(m.Source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Add overlay to all writable mounts, except when mapping an individual file.
|
||||
useOverlay = conf.Overlay && !mountFlags(m.Options).ReadOnly && fi.Mode().IsDir()
|
||||
default:
|
||||
// TODO: Support all the mount types and make this a
|
||||
// fatal error. Most applications will "just work" without
|
||||
|
||||
Reference in New Issue
Block a user