@@ -39,13 +39,26 @@ type ImageDiff struct {
3939 PartitionTable PartitionTableDiff `json:"partitionTable,omitempty"`
4040 Partitions PartitionDiff `json:"partitions,omitempty"`
4141 EFIBinaries EFIBinaryDiff `json:"efiBinaries,omitempty"`
42+ Verity * VerityDiff `json:"verity,omitempty" yaml:"verity,omitempty"`
4243}
4344
4445// MetaDiff represents differences in image-level metadata.
4546type MetaDiff struct {
4647 SizeBytes * ValueDiff [int64 ] `json:"sizeBytes,omitempty"`
4748}
4849
50+ // VerityDiff represents differences in dm-verity configuration.
51+ type VerityDiff struct {
52+ Added * VerityInfo `json:"added,omitempty" yaml:"added,omitempty"`
53+ Removed * VerityInfo `json:"removed,omitempty" yaml:"removed,omitempty"`
54+ Changed bool `json:"changed,omitempty" yaml:"changed,omitempty"`
55+
56+ Enabled * ValueDiff [bool ] `json:"enabled,omitempty" yaml:"enabled,omitempty"`
57+ Method * ValueDiff [string ] `json:"method,omitempty" yaml:"method,omitempty"`
58+ RootDevice * ValueDiff [string ] `json:"rootDevice,omitempty" yaml:"rootDevice,omitempty"`
59+ HashPartition * ValueDiff [int ] `json:"hashPartition,omitempty" yaml:"hashPartition,omitempty"`
60+ }
61+
4962// PartitionTableDiff represents differences in partition table-level fields.
5063type PartitionTableDiff struct {
5164 DiskGUID * ValueDiff [string ] `json:"diskGuid,omitempty"`
@@ -234,6 +247,12 @@ func CompareImages(from, to *ImageSummary) ImageCompareResult {
234247 res .Summary .Changed = true
235248 }
236249
250+ // --- dm-verity ---
251+ res .Diff .Verity = compareVerity (from .Verity , to .Verity )
252+ if res .Diff .Verity != nil && res .Diff .Verity .Changed {
253+ res .Summary .Changed = true
254+ }
255+
237256 // Deterministic ordering for stable JSON
238257 normalizeCompareResult (& res )
239258
@@ -284,6 +303,56 @@ func compareMeta(from, to ImageSummary) MetaDiff {
284303 return out
285304}
286305
306+ func compareVerity (from , to * VerityInfo ) * VerityDiff {
307+ // Both nil = no difference
308+ if from == nil && to == nil {
309+ return nil
310+ }
311+
312+ diff := & VerityDiff {}
313+
314+ // Added (to has verity, from doesn't)
315+ if from == nil && to != nil {
316+ diff .Added = to
317+ diff .Changed = true
318+ return diff
319+ }
320+
321+ // Removed (from has verity, to doesn't)
322+ if from != nil && to == nil {
323+ diff .Removed = from
324+ diff .Changed = true
325+ return diff
326+ }
327+
328+ // Both present
329+ if from .Enabled != to .Enabled {
330+ diff .Enabled = & ValueDiff [bool ]{From : from .Enabled , To : to .Enabled }
331+ diff .Changed = true
332+ }
333+
334+ if from .Method != to .Method {
335+ diff .Method = & ValueDiff [string ]{From : from .Method , To : to .Method }
336+ diff .Changed = true
337+ }
338+
339+ if from .RootDevice != to .RootDevice {
340+ diff .RootDevice = & ValueDiff [string ]{From : from .RootDevice , To : to .RootDevice }
341+ diff .Changed = true
342+ }
343+
344+ if from .HashPartition != to .HashPartition {
345+ diff .HashPartition = & ValueDiff [int ]{From : from .HashPartition , To : to .HashPartition }
346+ diff .Changed = true
347+ }
348+
349+ if ! diff .Changed {
350+ return nil
351+ }
352+
353+ return diff
354+ }
355+
287356// comparePartitionTable compares two PartitionTableSummary objects and returns a PartitionTableDiff.
288357func comparePartitionTable (from , to PartitionTableSummary ) PartitionTableDiff {
289358 var d PartitionTableDiff
@@ -751,6 +820,29 @@ func tallyDiffs(d ImageDiff) diffTally {
751820
752821 tallyEFIBinaryDiff (& t , d .EFIBinaries )
753822
823+ // dm-verity changes are meaningful (security-critical)
824+ if d .Verity != nil && d .Verity .Changed {
825+ if d .Verity .Added != nil {
826+ t .addMeaningful (1 , "dm-verity enabled" )
827+ } else if d .Verity .Removed != nil {
828+ t .addMeaningful (1 , "dm-verity disabled" )
829+ } else {
830+ // Field changes
831+ if d .Verity .Enabled != nil {
832+ t .addMeaningful (1 , "dm-verity enabled status changed" )
833+ }
834+ if d .Verity .Method != nil {
835+ t .addMeaningful (1 , "dm-verity method changed" )
836+ }
837+ if d .Verity .RootDevice != nil {
838+ t .addMeaningful (1 , "dm-verity root device changed" )
839+ }
840+ if d .Verity .HashPartition != nil {
841+ t .addMeaningful (1 , "dm-verity hash partition changed" )
842+ }
843+ }
844+ }
845+
754846 return t
755847}
756848
0 commit comments