am 46b1b205: am da724f7a: Merge "Zero out blocks that may be touched by dm-verity."

* commit '46b1b2057d5700a03b3fa6e332a737a0ef2425ba':
  Zero out blocks that may be touched by dm-verity.
This commit is contained in:
Tao Bao
2015-07-10 21:16:20 +00:00
committed by Android Git Automerger
4 changed files with 73 additions and 14 deletions

View File

@@ -1253,7 +1253,23 @@ class BlockDifference(object):
script.AppendExtra('if range_sha1("%s", "%s") == "%s" then' % (
self.device, ranges_str,
self.tgt.TotalSha1(include_clobbered_blocks=True)))
script.Print('Verified the updated %s image.' % (partition,))
# Bug: 20881595
# Verify that extended blocks are really zeroed out.
if self.tgt.extended:
ranges_str = self.tgt.extended.to_string_raw()
script.AppendExtra('if range_sha1("%s", "%s") == "%s" then' % (
self.device, ranges_str,
self._HashZeroBlocks(self.tgt.extended.size())))
script.Print('Verified the updated %s image.' % (partition,))
script.AppendExtra(
'else\n'
' abort("%s partition has unexpected non-zero contents after OTA '
'update");\n'
'endif;' % (partition,))
else:
script.Print('Verified the updated %s image.' % (partition,))
script.AppendExtra(
'else\n'
' abort("%s partition has unexpected contents after OTA update");\n'
@@ -1286,6 +1302,15 @@ class BlockDifference(object):
return ctx.hexdigest()
def _HashZeroBlocks(self, num_blocks): # pylint: disable=no-self-use
"""Return the hash value for all zero blocks."""
zero_block = '\x00' * 4096
ctx = sha1()
for _ in range(num_blocks):
ctx.update(zero_block)
return ctx.hexdigest()
# TODO(tbao): Due to http://b/20939131, block 0 may be changed without
# remounting R/W. Will change the checking to a finer-grained way to
# mask off those bits.