<div dir="ltr"><div><div><div><div>Thanks again for feedback !<br></div>Yes, I can do some additional tests in order to isolate the problem.<br></div>I'm not that familiar with the code responsible for this so I'll ask for your help with a patch. It will be quicker that way.<br><br></div>Best regards<br></div>Mircea<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Feb 24, 2018 at 10:59 AM, Gilad Ben-Yossef <span dir="ltr"><<a href="mailto:gilad@benyossef.com" target="_blank">gilad@benyossef.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I'm adding the linux crypto mailing list because it seems relevant.<br>
<div><div class="h5"><br>
<br>
On Fri, Feb 23, 2018 at 2:25 PM, Gigi W <<a href="mailto:gigitekwork@gmail.com">gigitekwork@gmail.com</a>> wrote:<br>
> Thanks for the input!<br>
><br>
> See below<br>
><br>
><br>
> On Fri, Feb 23, 2018 at 10:53 AM Gilad Ben-Yossef <<a href="mailto:gilad@benyossef.com">gilad@benyossef.com</a>><br>
> wrote:<br>
>><br>
>> On Fri, Feb 23, 2018 at 10:30 AM, Gigi W <<a href="mailto:gigitekwork@gmail.com">gigitekwork@gmail.com</a>> wrote:<br>
>> > Hi<br>
>> ><br>
>> > I'm having some trouble using dm-verity for a squashfs root file system<br>
>> > 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<br>
>> > 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<br>
>> > 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<br>
>> > 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>
><br>
><br>
> This would explain some things, like the same speeds while reading from a<br>
> verity device, having the CONFIG_CRYPTO_DEV_ATMEL_SHA enabled and then<br>
> disabled, on the 4.8.4 kernel -> it was always using the sync API.<br>
><br>
>><br>
>><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>
><br>
><br>
> It looks like it.<br>
><br>
> From my understandings + tests described above, Atmel SHA hw accelerator<br>
> works correctly - output hashes are ok, dm-verity with other async crypto<br>
> accelerators is working ok,<br>
> but dm-verity + Atmel SHA hw accelerator don't play nice together.<br>
><br>
> I couldn't find anyone else complaining about this.<br>
><br>
<br>
</div></div>I agree that that the possibility that there is something wrong in the<br>
Atmel SHA accelerator is one possible direction.<br>
The other one is that there is something wrong in DM-Verity that only<br>
manifests under certain conditions when working with async crypto HW<br>
providers.<br>
I don't think it is the case, because I tested DM-Verity after my<br>
changes with the CryptoCell async HW provider and did not get any<br>
other bug reports, but I'd like to be sure.<br>
<br>
Can you do a little experiment? add debug printk to show the data<br>
being hashed, the hash produced by atmel and the expected<br>
pre-calculated hash.<br>
<br>
If the theory that there is something wrong with atmel accelerator, we<br>
can calculate the hash on the data with other means (software) and<br>
should get a different hash.<br>
<br>
If you are having trouble adding the printk's in the right place let<br>
me know and I'll create a patch for you to test.<br>
<br>
Cheers,<br>
Gilad<br>
<div class="HOEnZb"><div class="h5"><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>
</div></div></blockquote></div><br></div>