All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ye Li <ye.li@nxp.com>
To: "yocto@bsorensen.net" <yocto@bsorensen.net>,
	"u-boot@lists.denx.de" <u-boot@lists.denx.de>
Subject: Re: [EXT] [PATCH] crypto/fsl: Fallback to SW sha1/256 is misaligned buffers
Date: Mon, 6 Dec 2021 08:22:55 +0000	[thread overview]
Message-ID: <1638778968.48631.6.camel@nxp.com> (raw)
In-Reply-To: <20211105094238.39565-1-yocto@bsorensen.net>

On Fri, 2021-11-05 at 10:42 +0100, Christian Sørensen wrote:
> Caution: EXT Email
> 
> Problem:
> With U-Boot 2021.10, we currently cannot load a fitImage on our imx7d
> board, due to misaligned buffers.
> 
> Reason:
> Commit 92055e138f28 ("image: Drop if/elseif hash selection in
> calculate_hash()")
> changed the way the FIT were verified. Previously, SW sha1/256 were
> always
> used. Due to that commit, that can now be done in hardware.
> caam_hash requires both the input, pbuf, and output buffer, pout, to
> be
> aligned. E.g. for the kernel data, pbuf will be the data start
> address
> for the kernel. The data start address is dependent on how the FIT is
> constructed and what address the FIT is loaded to. I.e.; it is fairly
> likely that we have a case of pbuf to not be aligned. pout is even
> more
> likely to not be aligned since it is simply a stack variable declared
> in
> fit_image_check_hash in common/image-fit.c.
> So to rely upon both of these buffers to be aligned, makes errors
> fairly
> likely.
> 
> Solution:
> I wont propose copying the entire input buffer due to its size, so
> instead
> just fallback to use the sw sha1/sha256 if buffers is misaligned.
> 
> Signed-off-by: Christian Sørensen <yocto@bsorensen.net>
> ---
> 
>  drivers/crypto/fsl/fsl_hash.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/crypto/fsl/fsl_hash.c
> b/drivers/crypto/fsl/fsl_hash.c
> index 8b5c26db07..48dd10883e 100644
> --- a/drivers/crypto/fsl/fsl_hash.c
> +++ b/drivers/crypto/fsl/fsl_hash.c
> @@ -16,6 +16,9 @@
>  #include <hw_sha.h>
>  #include <asm/cache.h>
>  #include <linux/errno.h>
> +#include <u-boot/sha1.h>
> +#include <u-boot/sha256.h>
> +#include <image.h>
> 
>  #define CRYPTO_MAX_ALG_NAME    80
>  #define SHA1_DIGEST_SIZE        20
> @@ -176,8 +179,12 @@ int caam_hash(const unsigned char *pbuf,
> unsigned int buf_len,
> 
>         if (!IS_ALIGNED((uintptr_t)pbuf, ARCH_DMA_MINALIGN) ||
>             !IS_ALIGNED((uintptr_t)pout, ARCH_DMA_MINALIGN)) {
> -               puts("Error: Address arguments are not aligned\n");
> -               return -EINVAL;
> +               printf("Fallback to SW hash due to misaligned
> buffers\n");
> +               if (algo == SHA1)
> +                       sha1_csum_wd(pbuf, buf_len, pout,
> CHUNKSZ_SHA1);
> +               else
> +                       sha256_csum_wd(pbuf, buf_len, pout,
> CHUNKSZ_SHA256);
> +               return 0;

How about adding “#ifdef CONFIG_SHA1” and “#ifdef CONFIG_SHA256” here
?  Then it can depend on users’ selection to determine the fallback

Best regards,
Ye Li

>         }
> 
>         size = ALIGN(buf_len, ARCH_DMA_MINALIGN);
> --
> 2.25.1
> 

  reply	other threads:[~2021-12-06  8:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-05  9:42 [PATCH] crypto/fsl: Fallback to SW sha1/256 is misaligned buffers Christian Sørensen
2021-12-06  8:22 ` Ye Li [this message]
2022-02-08 10:45   ` [EXT] " Philip Oberfichtner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1638778968.48631.6.camel@nxp.com \
    --to=ye.li@nxp.com \
    --cc=u-boot@lists.denx.de \
    --cc=yocto@bsorensen.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.