intverity_hash_for_block(structdm_verity*v,structdm_verity_io*io,335sector_tblock,u8*digest,bool*is_zero)336{337intr=0,i;339if(likely(v->levels)){340/*
341 * First, we try to get the requested hash for
342 * the current block. If the hash block itself is
343 * verified, zero is returned. If it isn't, this
344 * function returns 1 and we fall back to whole
345 * chain verification.
346 */347r=verity_verify_level(v,io,block,0,true,digest);348if(likely(r<=0))349gotoout;350}352memcpy(digest,v->root_digest,v->digest_size);354for(i=v->levels-1;i>=0;i--){355r=verity_verify_level(v,io,block,i,false,digest);356if(unlikely(r))357gotoout;358}359out:360if(!r&&v->zero_digest)361*is_zero=!memcmp(v->zero_digest,digest,v->digest_size);362else363*is_zero=false;364365returnr;366}c123456789101112131415161718192021222324252627282930
structdm_verity{35structdm_dev*data_dev;36structdm_dev*hash_dev;37structdm_target*ti;38structdm_bufio_client*bufio;39char*alg_name;40structcrypto_ahash*tfm;41u8*root_digest;/* digest of the root block */42u8*salt;/* salt: its size is salt_size */43u8*zero_digest;/* digest for a zero block */44unsignedsalt_size;45sector_tdata_start;/* data offset in 512-byte sectors */46sector_thash_start;/* hash start in blocks */47sector_tdata_blocks;/* the number of data blocks */48sector_thash_blocks;/* the number of hash blocks */49unsignedchardata_dev_block_bits;/* log2(data blocksize) */50unsignedcharhash_dev_block_bits;/* log2(hash blocksize) */51unsignedcharhash_per_block_bits;/* log2(hashes in hash block) */52unsignedcharlevels;/* the number of tree levels */53unsignedcharversion;54unsigneddigest_size;/* digest size for the current hash algorithm */55unsignedintahash_reqsize;/* the size of temporary space for crypto */56inthash_failed;/* set to 1 if hash of any block failed */57enumverity_modemode;/* mode for handling verification errors */58unsignedcorrupted_errs;/* Number of errors for corrupted blocks */5960structworkqueue_struct*verify_wq;6162/* starting blocks for each tree level. 0 is the lowest level. */63sector_thash_level_block[DM_VERITY_MAX_LEVELS];6465structdm_verity_fec*fec;/* forward error correction */66unsignedlong*validated_blocks;/* bitset blocks validated */6768char*signature_key_desc;/* signature keyring reference */69};70c12345678910111213141516171819202122232425262728293031323334353637
astro@astrox:~/code/test$sudolvdisplay--maps/dev/mapper/ubuntu--vg-ubuntu--lv---Logicalvolume---LVPath/dev/ubuntu-vg/ubuntu-lvLVNameubuntu-lvVGNameubuntu-vgLVUUIDfSgsCj-fCWR-JeiN-WWQL-xPdv-T1gZ-QO9f9MLVWriteAccessread/writeLVCreationhost,timeubuntu-server,2023-05-0909:07:38+0000LVStatusavailable# open 1
LVSize49.25GiBCurrentLE12608Segments1AllocationinheritReadaheadsectorsauto-currentlysetto256Blockdevice253:0---Segments---Logicalextents0to12607:TypelinearPhysicalvolume/dev/sda3Physicalextents0to12607c123456789101112131415161718192021222324