mbox series

[v4,00/15] hw/misc/aspeed_hace: Fix SG Accumulative Hash Calculations

Message ID 20240807195122.2827364-1-alejandro.zeise@seagate.com (mailing list archive)
Headers show
Series hw/misc/aspeed_hace: Fix SG Accumulative Hash Calculations | expand

Message

Alejandro Zeise Aug. 7, 2024, 7:51 p.m. UTC
The goal of this patch series is to fix accumulative hashing support in the 
Aspeed HACE module. The issue that stemmed this patch was a failure to boot an
OpenBMC image using the "ast2600-evb" machine. The U-boot
2019.04 loader failed to verify image hashes.

These incorrect image hashes given by the HACE to the U-boot guest are due to 
an oversight in the HACE module. Previously when operating in 
scatter-gather accumulative mode, the HACE would cache the address provided by 
the guest which contained the source data. However, there was no deep copy, 
so when HACE generated the digest upon the reception of the final accumulative chunk 
the digest was incorrect, as the addresses provided had their regions overwritten
by that time.

This fix consists of two main steps:
* Add an accumulative hashing function to the qcrypto library
* Modify the HACE module to use the accumulative hashing functions

All the crypto library backends (nettle, gnutls, etc.) support accumulative hashing,
so it was trivial to create wrappers for those functions.

Changes in V4:
* Restructured patches so unit tests pass for each independently.
* Freeing hash context is now a void function.
* Added autoptr cleanup function definition for qcrypto_hash_free.
* Separated qcrypto_hash_update into qcrypto_hash_update and qcrypto_hash_updatev.
* Changed public hash functions to use afalg implementation correctly if support
  is enabled.
* Fixed accumulative hashing in afalg driver (pass MSG_MORE socket flag).

Changes in V3:
* Reworked crypto hash API with comments from Daniel
  * Creation/Deletion of contexts, updating, and finalizing
  * Modified existing API functions to use the new 4 main core functions
  * Added test for accumulative hashing
  * Added afalg driver implementation
* Fixed bug in HACE module where hash context fails to allocate,
  causing the HACE internal state to be incorrect and segfault.

Changes in V2:
* Fixed error checking bug in libgcrypt crypto backend of
  accumulate_bytesv

Alejandro Zeise (15):
  crypto: accumulative hashing API
  crypto/hash-glib: Implement new hash API
  crypto/hash-gcrypt: Implement new hash API
  crypto/hash-gnutls: Implement new hash API
  crypto/hash-nettle: Implement new hash API
  crypto/hash-afalg: Implement new hash API
  crypto/hash: Implement and use new hash API
  tests/unit/test-crypto-hash: accumulative hashing
  crypto/hash-glib: Remove old hash API functions
  crypto/hash-gcrypt: Remove old hash API functions
  crypto/hash-gnutls: Remove old hash API functions
  crypto/hash-nettle: Remove old hash API functions
  crypto/hash-afalg: Remove old hash API functions
  crypto/hashpriv: Remove old hash API function
  hw/misc/aspeed_hace: Fix SG Accumulative hashing

 crypto/hash-afalg.c           | 171 ++++++++++++++++++++++++----------
 crypto/hash-gcrypt.c          | 110 ++++++++++++----------
 crypto/hash-glib.c            |  96 ++++++++++++-------
 crypto/hash-gnutls.c          |  92 +++++++++++-------
 crypto/hash-nettle.c          |  78 ++++++++++------
 crypto/hash.c                 | 163 +++++++++++++++++++++++++-------
 crypto/hashpriv.h             |  13 ++-
 hw/misc/aspeed_hace.c         |  94 ++++++++++---------
 include/crypto/hash.h         | 119 +++++++++++++++++++++++
 include/hw/misc/aspeed_hace.h |   4 +
 include/qemu/iov.h            |  26 ++++++
 tests/unit/test-crypto-hash.c |  48 ++++++++++
 util/iov.c                    |  22 +++--
 13 files changed, 753 insertions(+), 283 deletions(-)

Comments

Philippe Mathieu-Daudé Aug. 7, 2024, 8:01 p.m. UTC | #1
Hi Alejandro,

On 7/8/24 21:51, Alejandro Zeise wrote:
> The goal of this patch series is to fix accumulative hashing support in the
> Aspeed HACE module. The issue that stemmed this patch was a failure to boot an
> OpenBMC image using the "ast2600-evb" machine. The U-boot
> 2019.04 loader failed to verify image hashes.


> Alejandro Zeise (15):
>    crypto: accumulative hashing API
>    crypto/hash-glib: Implement new hash API
>    crypto/hash-gcrypt: Implement new hash API
>    crypto/hash-gnutls: Implement new hash API
>    crypto/hash-nettle: Implement new hash API
>    crypto/hash-afalg: Implement new hash API
>    crypto/hash: Implement and use new hash API
>    tests/unit/test-crypto-hash: accumulative hashing
>    crypto/hash-glib: Remove old hash API functions
>    crypto/hash-gcrypt: Remove old hash API functions
>    crypto/hash-gnutls: Remove old hash API functions
>    crypto/hash-nettle: Remove old hash API functions
>    crypto/hash-afalg: Remove old hash API functions
>    crypto/hashpriv: Remove old hash API function
>    hw/misc/aspeed_hace: Fix SG Accumulative hashing

>   13 files changed, 753 insertions(+), 283 deletions(-)

Even without the unit test this is still more than 700 LoC,
which seems a huge patchset to merge while we are in freeze
period. Do you expect this to be in the next v9.1.0 release?

Regards,

Phil.
Alejandro Zeise Aug. 7, 2024, 8:30 p.m. UTC | #2
Hi Phil,

> This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
>
>
> Hi Alejandro,
>
> On 7/8/24 21:51, Alejandro Zeise wrote:
> > The goal of this patch series is to fix accumulative hashing support 
> > in the Aspeed HACE module. The issue that stemmed this patch was a 
> > failure to boot an OpenBMC image using the "ast2600-evb" machine. The 
> > U-boot
> > 2019.04 loader failed to verify image hashes.
>
>
> > Alejandro Zeise (15):
> >    crypto: accumulative hashing API
> >    crypto/hash-glib: Implement new hash API
> >    crypto/hash-gcrypt: Implement new hash API
> >    crypto/hash-gnutls: Implement new hash API
> >    crypto/hash-nettle: Implement new hash API
> >    crypto/hash-afalg: Implement new hash API
> >    crypto/hash: Implement and use new hash API
> >    tests/unit/test-crypto-hash: accumulative hashing
> >    crypto/hash-glib: Remove old hash API functions
> >    crypto/hash-gcrypt: Remove old hash API functions
> >    crypto/hash-gnutls: Remove old hash API functions
> >    crypto/hash-nettle: Remove old hash API functions
> >    crypto/hash-afalg: Remove old hash API functions
> >    crypto/hashpriv: Remove old hash API function
> >    hw/misc/aspeed_hace: Fix SG Accumulative hashing
>
> >   13 files changed, 753 insertions(+), 283 deletions(-)

> Even without the unit test this is still more than 700 LoC, which seems a huge patchset to merge while we are in freeze period. Do you expect this to be in the next v9.1.0 release?
>
> Regards,
>
>  Phil.

I do understand this involves of changes, and don't expect this to be in the next release.
I'm not quite familiar with the process regarding versioning (this is my first ever patch), but I do not see a need to rush these changes.

Thanks,
Alejandro
Daniel P. Berrangé Aug. 8, 2024, 8:46 a.m. UTC | #3
On Wed, Aug 07, 2024 at 10:01:40PM +0200, Philippe Mathieu-Daudé wrote:
> Hi Alejandro,
> 
> On 7/8/24 21:51, Alejandro Zeise wrote:
> > The goal of this patch series is to fix accumulative hashing support in the
> > Aspeed HACE module. The issue that stemmed this patch was a failure to boot an
> > OpenBMC image using the "ast2600-evb" machine. The U-boot
> > 2019.04 loader failed to verify image hashes.
> 
> 
> > Alejandro Zeise (15):
> >    crypto: accumulative hashing API
> >    crypto/hash-glib: Implement new hash API
> >    crypto/hash-gcrypt: Implement new hash API
> >    crypto/hash-gnutls: Implement new hash API
> >    crypto/hash-nettle: Implement new hash API
> >    crypto/hash-afalg: Implement new hash API
> >    crypto/hash: Implement and use new hash API
> >    tests/unit/test-crypto-hash: accumulative hashing
> >    crypto/hash-glib: Remove old hash API functions
> >    crypto/hash-gcrypt: Remove old hash API functions
> >    crypto/hash-gnutls: Remove old hash API functions
> >    crypto/hash-nettle: Remove old hash API functions
> >    crypto/hash-afalg: Remove old hash API functions
> >    crypto/hashpriv: Remove old hash API function
> >    hw/misc/aspeed_hace: Fix SG Accumulative hashing
> 
> >   13 files changed, 753 insertions(+), 283 deletions(-)
> 
> Even without the unit test this is still more than 700 LoC,
> which seems a huge patchset to merge while we are in freeze
> period. Do you expect this to be in the next v9.1.0 release?

No, I'm not going to queue it for this release, I will put it
into my queue for 9.2.0

With regards,
Daniel