Skip to content

Commit

Permalink
lxd/storage/backend/lxd: Improve volume name validation in CreateCust…
Browse files Browse the repository at this point in the history
…omVolumeFromBackup

Signed-off-by: Thomas Parrott <[email protected]>
  • Loading branch information
tomponline committed Apr 5, 2024
1 parent 9ef74cf commit b0ad804
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion lxd/storage/backend_lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7188,6 +7188,31 @@ func (b *lxdBackend) CreateCustomVolumeFromBackup(srcBackup backup.Info, srcData
return fmt.Errorf("Valid volume snapshot config not found in index")
}

// Validate the names in the index.yaml file as these could be malicious.
err := ValidVolumeName(srcBackup.Name)
if err != nil {
return err
}

err = ValidVolumeName(srcBackup.Config.Volume.Name)
if err != nil {
return err
}

for _, snapName := range srcBackup.Snapshots {
err = ValidVolumeName(snapName)
if err != nil {
return err
}
}

for _, snap := range srcBackup.Config.VolumeSnapshots {
err = ValidVolumeName(snap.Name)
if err != nil {
return err
}
}

// Check whether we are allowed to create volumes.
req := api.StorageVolumesPost{
StorageVolumePut: api.StorageVolumePut{
Expand All @@ -7196,7 +7221,7 @@ func (b *lxdBackend) CreateCustomVolumeFromBackup(srcBackup backup.Info, srcData
Name: srcBackup.Name,
}

err := b.state.DB.Cluster.Transaction(b.state.ShutdownCtx, func(ctx context.Context, tx *db.ClusterTx) error {
err = b.state.DB.Cluster.Transaction(b.state.ShutdownCtx, func(ctx context.Context, tx *db.ClusterTx) error {
return project.AllowVolumeCreation(b.state.GlobalConfig, tx, srcBackup.Project, req)
})
if err != nil {
Expand Down

0 comments on commit b0ad804

Please sign in to comment.