Skip to content

Commit 9de6d51

Browse files
committed
Checking for protected dirs must be against mountPoint and not location
The validation code was written at a time when all mounts were mounted at `location` inside the guest because there was no separate `mountPoint` setting. Now that `mountPoint` exists, the only validation for `location` is that the path exists on the host and designates a directory. All validation to protect guest directories must be done against `mountPoint`. Signed-off-by: Jan Dubois <[email protected]>
1 parent f95997c commit 9de6d51

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

pkg/limayaml/validate.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,6 @@ func Validate(y *LimaYAML, warn bool) error {
152152
if err != nil {
153153
return fmt.Errorf("field `mounts[%d].location` refers to an unexpandable path: %q: %w", i, f.Location, err)
154154
}
155-
switch loc {
156-
case "/", "/bin", "/dev", "/etc", "/home", "/opt", "/sbin", "/tmp", "/usr", "/var":
157-
return fmt.Errorf("field `mounts[%d].location` must not be a system path such as /etc or /usr", i)
158-
// home directory defined in "cidata.iso:/user-data"
159-
case *y.User.Home:
160-
return fmt.Errorf("field `mounts[%d].location` is the reserved internal home directory", i)
161-
}
162-
163155
st, err := os.Stat(loc)
164156
if err != nil {
165157
if !errors.Is(err, os.ErrNotExist) {
@@ -169,6 +161,14 @@ func Validate(y *LimaYAML, warn bool) error {
169161
return fmt.Errorf("field `mounts[%d].location` refers to a non-directory path: %q: %w", i, f.Location, err)
170162
}
171163

164+
switch *f.MountPoint {
165+
case "/", "/bin", "/dev", "/etc", "/home", "/opt", "/sbin", "/tmp", "/usr", "/var":
166+
return fmt.Errorf("field `mounts[%d].mountPoint` must not be a system path such as /etc or /usr", i)
167+
// home directory defined in "cidata.iso:/user-data"
168+
case *y.User.Home:
169+
return fmt.Errorf("field `mounts[%d].mountPoint` is the reserved internal home directory %q", i, *y.User.Home)
170+
}
171+
172172
if _, err := units.RAMInBytes(*f.NineP.Msize); err != nil {
173173
return fmt.Errorf("field `msize` has an invalid value: %w", err)
174174
}

0 commit comments

Comments
 (0)