GitHub Security Advisory: GHSA-x5r6-jr56-89pv
Package: github.com/lxc/incus/v6/cmd/incusd (GO)
Severity: MODERATE (CVSS 6.5)
CWE: CWE-476: NULL Pointer Dereference
Vulnerable versions: <= 6.23.0
Patched in: unpatched

Summary: Incus has Nil Dereferences on Restore via Malformed YAML

Details:
### Summary

### Details
It was found that backup.GetInfo() trusts the inline backup/index.yaml config when present and only falls back to parsing the legacy backup/container/backup.yaml file if result.Config == nil. As a result, an archive can carry a valid inline config that passes the initial import preflight while also carrying a malformed legacy backup/container/backup.yaml file that is reparsed later from the restored file system.

ParseConfigYamlFile() accepts YAML documents with no container section, and multiple downstream consumers then dereference .Container without checking for nil. Confirmed examples in the instance restore and import flow include backup.UpdateInstanceConfig() and internalImportFromBackup().

An authenticated user with permission to import instance backups may be able to crash the Incus daemon with a crafted backup archive whose inline backup/index.yaml is valid but whose extracted legacy backup.yaml omits container. The crash occurs in the restore path after archive extraction has begun.

The flow is as follows:
A crafted backup archive contains a valid backup/index.yaml file together with a malformed backup/container/backup.yaml file that omits the container section.
backup.GetInfo() parses backup/index.yaml successfully, so bInfo.Config is populated from the inline config.
Because result.Config != nil, GetInfo() does not fall back to backup/container/backup.yaml.
instances_post.go then builds the request from bInfo.Config.Container, which succeeds because the inline config is valid.
Later, storage unpack extracts backup/container/backup.yaml into the instance volume as <mountPath>/backup.yaml.
backend.go then calls backup.UpdateInstanceConfig(..., mountPath), which reparses <mountPath>/backup.yaml through ParseConfigYamlFile().
Because ParseConfigYamlFile() accepts YAML with no container section, backup.Container == nil, and later access to backup.Container.Devices or backup.Container.ExpandedDevices can trigger a nil-pointer dereference.


Affected Files:
 - https://github.com/lxc/incus/blob/v6.22.0/internal/server/backup/backup_info.go#L87
 - https://github.com/lxc/incus/blob/v6.22.0/internal/server/backup/backup_info.go#L115
 - https://github.com/lxc/incus/blob/v6.22.0/internal/server/backup/backup_config_utils.go#L85
 - https://github.com/lxc/incus/blob/v6.22.0/internal/server/backup/backup_config_utils.go#L159
 - https://github.com/lxc/incus/blob/v6.22.0/internal/server/storage/backend.go#L809
 - https://github.com/lxc/incus/blob/v6.22.0/cmd/incusd/api_internal.go#L749

The initial backup-metadata parser prefers inline backup/index.yaml content:

Affected Code:
```
if hdr.Name == backupIndexPath {
    err = yaml.NewDecoder(tr).Decode(&result)
```

The legacy backup/container/backup.yaml file is only parsed if the inline config is absent:

Affected Code:
```
if result.Config == nil && hdr.Name == "backup/container/backup.yaml" {
    err = yaml.NewDecoder(tr).Decode(&result.Config)
```

ParseConfigYamlFile() ac