tree: cdaebb26f6893be4ba51b4a56f4de6d893d09dd7 [path history] [tgz]
  1. ebpf/
  2. corrupted_hashtree.txt
  3. corrupted_image_with_hashtree.txt
  4. hashtree_truncated.txt
  5. README.md
  6. root_hash.txt
  7. simple_ext4.img
  8. valid_image_with_hashtree.txt
src/starnix/tests/syscalls/rust/data/README.md

syscalls test data

ext4 image

Created without the 64bit feature with:

  • truncate -s 1M simple_ext4.img
  • mkfs.ext4 simple_ext4.img -O ^64bit
  • sudo mkdir /mnt/tmp
  • sudo mount -oloop simple_ext4.img /mnt/tmp
  • sudo cp hello_world.txt /mnt/tmp/
  • sudo umount /mnt/tmp
  • e2fsck -f simple_ext4.img
  • resize2fs -M simple_ext4.img (counting number of reported blocks)
  • truncate -o --size NN simple_ext4.img (where NN=number of blocks above)

hash tree file

The DM_TABLE_LOAD ioctl for dm-verity requires the user to pass in a hashtree file that contains a merkle tree that is generated from the contents of the ext4 image. The following commands allow us to make use of the losetup and veritysetup command line tools to both generate the hashtree file.

  1. Set up two loop devices. One backing the ext4 image and one backing the hashtree file.
  • sudo losetup -f src/starnix/tests/syscalls/rust/data/simple_ext4.img
  • sudo dd if=/dev/zero bs=4k conv=notrunc oflag=append count=2 of=/tmp/hashtree

NOTE: count here is the number of blocks that we need to store the merkle tree. Can be adjusted for larger ext4 images.

  • sudo losetup -f /tmp/hashtree
  1. Figure out which loop devices are associated with which files.
  • sudo losetup -a

    e.g.

    /dev/loop19: (/usr/local/google/home/nikitajindal/fuchsia/src/starnix/tests/syscalls/rust/data/simple_ext4.img)

    /dev/loop20: (/tmp/hashtree)

  1. Use veritysetup format to generate the merkle tree and populate the hashtree file with it. Note that veritysetup format takes several optional arguments. Here we just set the salt. The format command will print out the root hash of the merkle tree. The root hash is copied into data/root_hash.txt.
  • sudo veritysetup format /dev/loop19 /dev/loop20 --salt ffffffffffffffff
  1. Copy the contents of /tmp/hashtree into data/hashtree_truncated.txt, removing the first block.
  • dd if=/tmp/hashtree of=src/starnix/tests/syscalls/rust/data/hashtree_truncated.txt bs=1 skip=4096