Skip to content

Commit

Permalink
lxd/apparmor/instance: Update instanceProfile to use start time firmw…
Browse files Browse the repository at this point in the history
…are path

Rather than allowing access to all potential firmware directories.

Signed-off-by: Thomas Parrott <[email protected]>
  • Loading branch information
tomponline committed Sep 4, 2024
1 parent 797ea06 commit 9a40488
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
23 changes: 19 additions & 4 deletions lxd/apparmor/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ type instance interface {
DevicesPath() string
}

type instanceVM interface {
instance

FirmwarePath() string
}

// InstanceProfileName returns the instance's AppArmor profile name.
func InstanceProfileName(inst instance) string {
path := shared.VarPath("")
Expand Down Expand Up @@ -194,9 +200,18 @@ func instanceProfile(sysOS *sys.OS, inst instance) (string, error) {
return "", err
}

qemuFwPathsArr, err := util.GetQemuFwPaths()
if err != nil {
return "", err
vmInst, ok := inst.(instanceVM)
if !ok {
return "", fmt.Errorf("Instance is not VM type")
}

// Get start time firmware path to allow access to it.
firmwarePath := vmInst.FirmwarePath()
if firmwarePath != "" {
firmwarePath, err = filepath.EvalSymlinks(firmwarePath)
if err != nil {
return "", fmt.Errorf("Failed finding firmware: %w", err)
}
}

execPath := util.GetExecPath()
Expand All @@ -216,7 +231,7 @@ func instanceProfile(sysOS *sys.OS, inst instance) (string, error) {
"rootPath": rootPath,
"snap": shared.InSnap(),
"userns": sysOS.RunningInUserNS,
"qemuFwPaths": qemuFwPathsArr,
"firmwarePath": firmwarePath,
"snapExtQemuPrefix": os.Getenv("SNAP_QEMU_PREFIX"),
})
if err != nil {
Expand Down
10 changes: 3 additions & 7 deletions lxd/apparmor/instance_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,9 @@ profile "{{ .name }}" flags=(attach_disconnected,mediate_deleted) {
{{- end }}
{{- end }}
{{if .qemuFwPaths -}}
# Entries from LXD_OVMF_PATH or LXD_QEMU_FW_PATH
{{range $index, $element := .qemuFwPaths}}
{{$element}}/OVMF_CODE.fd kr,
{{$element}}/OVMF_CODE.*.fd kr,
{{$element}}/*bios*.bin kr,
{{- end }}
{{if .firmwarePath -}}
# Firmware path
{{ .firmwarePath }} kr,
{{- end }}
{{- if .raw }}
Expand Down

0 comments on commit 9a40488

Please sign in to comment.