public inbox for linux-crypto@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Nathan Huckleberry <nhuck@google.com>
Cc: herbert@gondor.apana.org.au, ardb@kernel.org,
	bgoncalv@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
	davem@davemloft.net, hpa@zytor.com, linux-crypto@vger.kernel.org,
	linux-kernel@vger.kernel.org, mingo@redhat.com,
	tglx@linutronix.de, x86@kernel.org
Subject: Re: [PATCH v2] crypto: x86/polyval - Fix crashes when keys are not 16-byte aligned
Date: Tue, 18 Oct 2022 15:39:24 -0700	[thread overview]
Message-ID: <Y08rHF09/qxCVK+K@sol.localdomain> (raw)
In-Reply-To: <20221018215623.866014-1-nhuck@google.com>

On Tue, Oct 18, 2022 at 02:56:23PM -0700, Nathan Huckleberry wrote:
> -static void internal_polyval_update(const struct polyval_tfm_ctx *keys,
> +static inline struct polyval_tfm_ctx *polyval_tfm_ctx(const void *raw_ctx)
> +{
> +	unsigned long addr = (unsigned long)raw_ctx;
> +	unsigned long align = POLYVAL_ALIGN;
> +
> +	if (align <= crypto_tfm_ctx_alignment())
> +		align = 1;
> +	return (struct polyval_tfm_ctx *)ALIGN(addr, align);
> +}

This could just use PTR_ALIGN.  Also, checking for POLYVAL_ALIGN <=
crypto_tfm_ctx_alignment() isn't necessary.

> +
> +static void internal_polyval_update(const void *raw_keys,
>  	const u8 *in, size_t nblocks, u8 *accumulator)
>  {
> +	const struct polyval_tfm_ctx *keys = polyval_tfm_ctx(raw_keys);

This is being passed a struct polyval_tfm_ctx.  There's no need to cast it back
to a void pointer and align it again redundantly.

>  	if (likely(crypto_simd_usable())) {
>  		kernel_fpu_begin();
>  		clmul_polyval_update(keys, in, nblocks, accumulator);
> @@ -102,7 +117,8 @@ static int polyval_x86_update(struct shash_desc *desc,
>  			 const u8 *src, unsigned int srclen)
>  {
>  	struct polyval_desc_ctx *dctx = shash_desc_ctx(desc);
> -	const struct polyval_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm);
> +	const struct polyval_tfm_ctx *tctx =
> +	    polyval_tfm_ctx(crypto_shash_ctx(desc->tfm));
>  	u8 *pos;
>  	unsigned int nblocks;
>  	unsigned int n;

It would make more sense to have the polyval_tfm_ctx() function take in the
struct crypto_shash.

How about using the following:

static inline struct polyval_tfm_ctx *polyval_tfm_ctx(struct crypto_shash *tfm)
{
        return PTR_ALIGN(crypto_shash_ctx(tfm), POLYVAL_ALIGN);
}

- Eric

  reply	other threads:[~2022-10-18 22:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-17 22:26 [PATCH] crypto: x86/polyval - Fix crashes when keys are not 16-byte aligned Nathan Huckleberry
2022-10-17 23:02 ` Eric Biggers
2022-10-17 23:38   ` Nathan Huckleberry
2022-10-18  0:12     ` Eric Biggers
2022-10-18  4:03       ` Herbert Xu
2022-10-18 21:56         ` [PATCH v2] " Nathan Huckleberry
2022-10-18 22:39           ` Eric Biggers [this message]
2022-10-18 23:04             ` [PATCH v3] " Nathan Huckleberry
2022-10-18 23:12               ` Eric Biggers
2022-10-19 12:13               ` Bruno Goncalves
2022-10-21 11:39               ` Herbert Xu

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=Y08rHF09/qxCVK+K@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=ardb@kernel.org \
    --cc=bgoncalv@redhat.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=hpa@zytor.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nhuck@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox