<div dir="ltr"><div>Thanks for the input!<br></div><br>See below <br><br><br><div class="gmail_quote"><div dir="ltr">On Fri, Feb 23, 2018 at 10:53 AM Gilad Ben-Yossef <<a href="mailto:gilad@benyossef.com" target="_blank">gilad@benyossef.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, Feb 23, 2018 at 10:30 AM, Gigi W <<a href="mailto:gigitekwork@gmail.com" target="_blank">gigitekwork@gmail.com</a>> wrote:<br>
> Hi<br>
><br>
> I'm having some trouble using dm-verity for a squashfs root file system that<br>
> seems to be related to the<br>
> Atmel SHA hw accelerator in the kernel, CONFIG_CRYPTO_DEV_ATMEL_SHA<br>
><br>
> Some info about my setup:<br>
> * I'm using a board with a SAMA5D4 CPU.<br>
> * I'm using Yocto rocko for building an image for that device.<br>
><br>
> The idea is that Using the 4.14.14 Kernel, Integrity checking using Kernel<br>
> crypto fails with Atmel SHA hw accelerator enabled in kernel.<br>
> By disabling it, `CONFIG_CRYPTO_DEV_ATMEL_SHA=<wbr>n`, and using the software<br>
> sha256 algo, integrity checking works as expected.<br>
> This is my kernel config [3]<br>
><br>
> Using the 4.8.4 Kernel and Atmel SHA hw accelerator enabled, everything was<br>
> ok.<br>
><br>
> This is what triggers the error during verified boot:<br>
><br>
> status=`veritysetup create vroot $root_dev $verity_dev --hash-offset<br>
> $hashoffset $root_hash`<br>
><br>
>     mount /dev/mapper/vroot /mnt/<br>
>     mount_ok=`cat /proc/mounts | grep mnt`<br>
>     if [ -z "$mount_ok" ] ; then<br>
>         echo "Failed to mount $root_dev on mnt/"<br>
>     else<br>
>         echo "Switch rootfs"<br>
>         exec switch_root -c /dev/console /mnt /sbin/init<br>
>     fi<br>
><br>
> The mount operation fails:<br>
><br>
> device-mapper: verity: 179:4: metadata block 2 is corrupted<br>
> EXT4-fs (dm-0): unable to read superblock<br>
> device-mapper: verity: 179:4: metadata block 2 is corrupted<br>
> EXT4-fs (dm-0): unable to read superblock<br>
> device-mapper: verity: 179:4: metadata block 2 is corrupted<br>
> EXT4-fs (dm-0): unable to read superblock<br>
> device-mapper: verity: 179:4: metadata block 2 is corrupted<br>
> SQUASHFS error: squashfs_read_data failed to read block 0x0<br>
> squashfs: SQUASHFS error: unable to read squashfs_super_block<br>
> device-mapper: verity: 179:4: metadata block 2 is corrupted<br>
> FAT-fs (dm-0): unable to read boot sector<br>
> mount: mounting /dev/mapper/vroot on /mnt/ failed: Input/output error<br>
> Failed to mount /dev/mmcblk0p4 on mnt/<br>
> reboot: Restarting system<br>
> Reboot failed -- System halted<br>
><br>
> Using veritysetup to verify the integrity against the hashes is successful,<br>
> as it's not using the kernel for that ...<br>
><br>
><br>
> So it looks like it something changed from 4.8.4 to 4.14.14.<br>
<br>
If I am not mistaken the Atmel SHA hw accelerator is an async (read:<br>
off CPU) crypto accelerator.<br>
 Up until 4.12 (I think...) DM-Verity did not use async crypto<br>
accelerators (even if present and have high<br>
priority). I've changed this is commit d1ac3ff008fb ("dm verity:<br>
switch to using asynchronous hash crypto API").<br></blockquote><div><br>This would explain some things, like the same speeds while reading from a verity device, having the <b>CONFIG_CRYPTO_DEV_ATMEL_SHA</b> enabled and then disabled, on the 4.8.4 kernel -> it was always using the sync API.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Is it possible that whatever issue you are seeing has always been<br>
there and when DM-Verity started using<br>
async. accelerators it was only exposed?<br></blockquote><div><br></div><div>It looks like it.<br><br>From my understandings + tests described above, Atmel SHA hw accelerator works correctly - output hashes are ok, dm-verity with other async crypto accelerators is working ok, <br>but dm-verity + Atmel SHA hw accelerator don't play nice together.</div><br></div><div class="gmail_quote">I couldn't find anyone else complaining about this.<br><br></div><div class="gmail_quote">Best regards.<br></div><div class="gmail_quote"><br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
> Using the 4.14.14 kernel, I removed the patches that were applied on the<br>
> atmel-sha.c file in the kernel, one by one, until I got the version from the<br>
> 4.8.4<br>
> Basically I reverted the changes from<br>
> here:<a href="https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/log/drivers/crypto/atmel-sha.c?h=v4.14.14" rel="noreferrer" target="_blank">https://git.kernel.org/<wbr>pub/scm/linux/kernel/git/<wbr>stable/linux-stable.git/log/<wbr>drivers/crypto/atmel-sha.c?h=<wbr>v4.14.14</a><br>
> until I got this:<br>
> <a href="https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/log/drivers/crypto/atmel-sha.c?h=v4.8.4" rel="noreferrer" target="_blank">https://git.kernel.org/pub/<wbr>scm/linux/kernel/git/stable/<wbr>linux-stable.git/log/drivers/<wbr>crypto/atmel-sha.c?h=v4.8.4</a><br>
><br>
> It still didn't work. I assumed something there broke the hashing, not the<br>
> case. It was still not working with all those commits reverted.<br>
><br>
> Furthermore, using the Cryptodev-linux module [1], and the sample [2],<br>
> adapted to use sha256, I tested the output hashes, with<br>
> CONFIG_CRYPTO_DEV_ATMEL_SHA enabled and then disabled.<br>
><br>
> I got the same results in both cases, hardware and software algorithm. So it<br>
> doesn't look like the SHA hw accelerator is broken.<br>
><br>
><br>
> Any help is appreciated !<br>
><br>
> Thanks in advanced and have a nice day.<br>
><br>
><br>
> [1] <a href="http://cryptodev-linux.org/documentation.html" rel="noreferrer" target="_blank">http://cryptodev-linux.org/<wbr>documentation.html</a><br>
> [2] <a href="https://github.com/nmav/cryptodev-linux/blob/master/examples/sha.c" rel="noreferrer" target="_blank">https://github.com/nmav/<wbr>cryptodev-linux/blob/master/<wbr>examples/sha.c</a><br>
> [3]<br>
> <a href="https://gist.githubusercontent.com/gmircea/6e1cc029ef5ed7a16b0fedb8b9524f66/raw/eece8a8faadd2de9373e150ef1daf3cf25f4135c/.config" rel="noreferrer" target="_blank">https://gist.<wbr>githubusercontent.com/gmircea/<wbr>6e1cc029ef5ed7a16b0fedb8b9524f<wbr>66/raw/<wbr>eece8a8faadd2de9373e150ef1daf3<wbr>cf25f4135c/.config</a><br>
><br>
><br>
> --<br>
> dm-devel mailing list<br>
> <a href="mailto:dm-devel@redhat.com" target="_blank">dm-devel@redhat.com</a><br>
> <a href="https://www.redhat.com/mailman/listinfo/dm-devel" rel="noreferrer" target="_blank">https://www.redhat.com/<wbr>mailman/listinfo/dm-devel</a><br>
<br>
<br>
<br>
--<br>
Gilad Ben-Yossef<br>
Chief Coffee Drinker<br>
<br>
"If you take a class in large-scale robotics, can you end up in a<br>
situation where the homework eats your dog?"<br>
 -- Jean-Baptiste Queru<br>
</blockquote></div></div>