@@ -393,20 +393,26 @@ func ifNil[T any](v *T) *T {
393393}
394394
395395func validateSpecForContainer (oldSpec , newSpec * specs.Spec , cName string ) error {
396- oldLinux , newLinux := ifNil (oldSpec .Linux ), ifNil (newSpec .Linux )
397- oldProcess , newProcess := ifNil (oldSpec .Process ), ifNil (newSpec .Process )
398- oldRoot , newRoot := ifNil (oldSpec .Root ), ifNil (newSpec .Root )
396+ validateStructMap := make (map [string ][2 ]any )
399397
398+ // Validate OCI version.
400399 if oldSpec .Version != newSpec .Version {
401400 return validateError ("OCI Version" , cName , oldSpec .Version , newSpec .Version )
402401 }
403- validateStructMap := make (map [string ][2 ]any )
404- validateStructMap ["Root" ] = [2 ]any {oldRoot , newRoot }
402+
403+ // Validate specs.Spec.Root. Note that Root.Path can change during restore.
404+ oldRoot , newRoot := ifNil (oldSpec .Root ), ifNil (newSpec .Root )
405+ if oldRoot .Readonly != newRoot .Readonly {
406+ return validateError ("Root.Readonly" , cName , oldRoot .Readonly , newRoot .Readonly )
407+ }
408+
409+ // Validate specs.Spec.Mounts.
405410 if err := validateMounts ("Mounts" , cName , oldSpec .Mounts , newSpec .Mounts ); err != nil {
406411 return err
407412 }
408413
409- // Validate specs.Process.
414+ // Validate specs.Spec.Process.
415+ oldProcess , newProcess := ifNil (oldSpec .Process ), ifNil (newSpec .Process )
410416 if oldProcess .Terminal != newProcess .Terminal {
411417 return validateError ("Terminal" , cName , oldProcess .Terminal , newProcess .Terminal )
412418 }
@@ -422,7 +428,8 @@ func validateSpecForContainer(oldSpec, newSpec *specs.Spec, cName string) error
422428 return err
423429 }
424430
425- // Validate specs.Linux.
431+ // Validate specs.Spec.Linux.
432+ oldLinux , newLinux := ifNil (oldSpec .Linux ), ifNil (newSpec .Linux )
426433 validateStructMap ["Sysctl" ] = [2 ]any {oldLinux .Sysctl , newLinux .Sysctl }
427434 validateStructMap ["Seccomp" ] = [2 ]any {oldLinux .Seccomp , newLinux .Seccomp }
428435 if err := validateDevices ("Devices" , cName , oldLinux .Devices , newLinux .Devices ); err != nil {
@@ -441,16 +448,18 @@ func validateSpecForContainer(oldSpec, newSpec *specs.Spec, cName string) error
441448 return err
442449 }
443450
451+ // Validate specs.Spec.Annotations.
452+ if err := validateAnnotations (cName , oldSpec .Annotations , newSpec .Annotations ); err != nil {
453+ return err
454+ }
455+
456+ // Validate all the structs collected in validateStructMap above.
444457 for key , val := range validateStructMap {
445458 if err := validateStruct (key , cName , val [0 ], val [1 ]); err != nil {
446459 return err
447460 }
448461 }
449462
450- if err := validateAnnotations (cName , oldSpec .Annotations , newSpec .Annotations ); err != nil {
451- return err
452- }
453-
454463 // TODO(b/359591006): Check other remaining fields for equality.
455464 return nil
456465}
0 commit comments