Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
runtime: readonly mounts should be readonly bindmount on the host
Browse files Browse the repository at this point in the history
So that we get protected at the VM boundary not just the guest kernel.

Signed-off-by: Peng Tao <bergwolf@hyper.sh>
  • Loading branch information
bergwolf committed Nov 2, 2020
1 parent c54378d commit 750419c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
14 changes: 2 additions & 12 deletions virtcontainers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ func (c *Container) shareFiles(m Mount, idx int, hostSharedDir, guestSharedDir s
} else {
// These mounts are created in the shared dir
mountDest := filepath.Join(hostSharedDir, filename)
if err := bindMount(c.ctx, m.Source, mountDest, false, "private"); err != nil {
if err := bindMount(c.ctx, m.Source, mountDest, m.ReadOnly, "private"); err != nil {
return "", false, err
}
// Save HostPath mount value into the mount list of the container.
Expand Down Expand Up @@ -557,22 +557,12 @@ func (c *Container) mountSharedDirMounts(hostSharedDir, guestSharedDir string) (
continue
}

// Check if mount is readonly, let the agent handle the readonly mount
// within the VM.
readonly := false
for _, flag := range m.Options {
if flag == "ro" {
readonly = true
break
}
}

sharedDirMount := Mount{
Source: guestDest,
Destination: m.Destination,
Type: m.Type,
Options: m.Options,
ReadOnly: readonly,
ReadOnly: m.ReadOnly,
}

sharedDirMounts[sharedDirMount.Destination] = sharedDirMount
Expand Down
8 changes: 8 additions & 0 deletions virtcontainers/pkg/oci/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,19 @@ func cmdEnvs(spec specs.Spec, envs []types.EnvVar) []types.EnvVar {
}

func newMount(m specs.Mount) vc.Mount {
readonly := false
for _, flag := range m.Options {
if flag == "ro" {
readonly = true
break
}
}
return vc.Mount{
Source: m.Source,
Destination: m.Destination,
Type: m.Type,
Options: m.Options,
ReadOnly: readonly,
}
}

Expand Down

0 comments on commit 750419c

Please sign in to comment.