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

Commit 509eb6f

Browse files
bergwolfegernst
authored andcommitted
runtime: readonly mounts should be readonly bindmount on the host
So that we get protected at the VM boundary not just the guest kernel. Signed-off-by: Peng Tao <[email protected]>
1 parent 0b8ef4d commit 509eb6f

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

virtcontainers/container.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ func (c *Container) shareFiles(m Mount, idx int, hostSharedDir, guestSharedDir s
481481
} else {
482482
// These mounts are created in the shared dir
483483
mountDest := filepath.Join(hostSharedDir, filename)
484-
if err := bindMount(c.ctx, m.Source, mountDest, false, "private"); err != nil {
484+
if err := bindMount(c.ctx, m.Source, mountDest, m.ReadOnly, "private"); err != nil {
485485
return "", false, err
486486
}
487487
// Save HostPath mount value into the mount list of the container.
@@ -557,22 +557,12 @@ func (c *Container) mountSharedDirMounts(hostSharedDir, guestSharedDir string) (
557557
continue
558558
}
559559

560-
// Check if mount is readonly, let the agent handle the readonly mount
561-
// within the VM.
562-
readonly := false
563-
for _, flag := range m.Options {
564-
if flag == "ro" {
565-
readonly = true
566-
break
567-
}
568-
}
569-
570560
sharedDirMount := Mount{
571561
Source: guestDest,
572562
Destination: m.Destination,
573563
Type: m.Type,
574564
Options: m.Options,
575-
ReadOnly: readonly,
565+
ReadOnly: m.ReadOnly,
576566
}
577567

578568
sharedDirMounts[sharedDirMount.Destination] = sharedDirMount

virtcontainers/pkg/oci/utils.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,19 @@ func cmdEnvs(spec specs.Spec, envs []types.EnvVar) []types.EnvVar {
165165
}
166166

167167
func newMount(m specs.Mount) vc.Mount {
168+
readonly := false
169+
for _, flag := range m.Options {
170+
if flag == "ro" {
171+
readonly = true
172+
break
173+
}
174+
}
168175
return vc.Mount{
169176
Source: m.Source,
170177
Destination: m.Destination,
171178
Type: m.Type,
172179
Options: m.Options,
180+
ReadOnly: readonly,
173181
}
174182
}
175183

0 commit comments

Comments
 (0)