Skip to content

Commit

Permalink
Checking for protected dirs must be against mountPoint and not location
Browse files Browse the repository at this point in the history
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 <jan.dubois@suse.com>
  • Loading branch information
jandubois committed Feb 6, 2025
1 parent f95997c commit 9de6d51
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/limayaml/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,6 @@ func Validate(y *LimaYAML, warn bool) error {
if err != nil {
return fmt.Errorf("field `mounts[%d].location` refers to an unexpandable path: %q: %w", i, f.Location, err)
}
switch loc {
case "/", "/bin", "/dev", "/etc", "/home", "/opt", "/sbin", "/tmp", "/usr", "/var":
return fmt.Errorf("field `mounts[%d].location` must not be a system path such as /etc or /usr", i)
// home directory defined in "cidata.iso:/user-data"
case *y.User.Home:
return fmt.Errorf("field `mounts[%d].location` is the reserved internal home directory", i)
}

st, err := os.Stat(loc)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
Expand All @@ -169,6 +161,14 @@ func Validate(y *LimaYAML, warn bool) error {
return fmt.Errorf("field `mounts[%d].location` refers to a non-directory path: %q: %w", i, f.Location, err)
}

switch *f.MountPoint {
case "/", "/bin", "/dev", "/etc", "/home", "/opt", "/sbin", "/tmp", "/usr", "/var":
return fmt.Errorf("field `mounts[%d].mountPoint` must not be a system path such as /etc or /usr", i)
// home directory defined in "cidata.iso:/user-data"
case *y.User.Home:
return fmt.Errorf("field `mounts[%d].mountPoint` is the reserved internal home directory %q", i, *y.User.Home)
}

if _, err := units.RAMInBytes(*f.NineP.Msize); err != nil {
return fmt.Errorf("field `msize` has an invalid value: %w", err)
}
Expand Down

0 comments on commit 9de6d51

Please # to comment.