From: Kees Cook <keescook@chromium.org>
To: "Herbert Xu" <herbert@gondor.apana.org.au>,
"João Moreira" <joao.moreira@intel.com>,
"Sami Tolvanen" <samitolvanen@google.com>,
"David S. Miller" <davem@davemloft.net>,
"Ard Biesheuvel" <ard.biesheuvel@linaro.org>,
"Stephan Mueller" <smueller@chronox.de>,
x86@kernel.org, linux-crypto@vger.kernel.org,
linux-kernel@vger.kernel.org,
kernel-hardening@lists.openwall.com
Subject: Re: [PATCH v5 8/8] crypto, x86/sha: Eliminate casts on asm implementations
Date: Thu, 21 Nov 2019 15:14:19 -0800 [thread overview]
Message-ID: <201911211512.6A86399@keescook> (raw)
In-Reply-To: <20191113195529.GD221701@gmail.com>
On Wed, Nov 13, 2019 at 11:55:30AM -0800, Eric Biggers wrote:
> On Wed, Nov 13, 2019 at 10:25:16AM -0800, Kees Cook wrote:
> > In order to avoid CFI function prototype mismatches, this removes the
> > casts on assembly implementations of sha1/256/512 accelerators. The
> > safety checks from BUILD_BUG_ON() remain.
> >
> > Signed-off-by: Kees Cook <keescook@chromium.org>
> > ---
> > arch/x86/crypto/sha1_ssse3_glue.c | 61 ++++++++++++-----------------
> > arch/x86/crypto/sha256_ssse3_glue.c | 31 +++++++--------
> > arch/x86/crypto/sha512_ssse3_glue.c | 28 ++++++-------
> > 3 files changed, 50 insertions(+), 70 deletions(-)
> >
> > diff --git a/arch/x86/crypto/sha1_ssse3_glue.c b/arch/x86/crypto/sha1_ssse3_glue.c
> > index 639d4c2fd6a8..a151d899f37a 100644
> > --- a/arch/x86/crypto/sha1_ssse3_glue.c
> > +++ b/arch/x86/crypto/sha1_ssse3_glue.c
> > @@ -27,11 +27,8 @@
> > #include <crypto/sha1_base.h>
> > #include <asm/simd.h>
> >
> > -typedef void (sha1_transform_fn)(u32 *digest, const char *data,
> > - unsigned int rounds);
> > -
> > static int sha1_update(struct shash_desc *desc, const u8 *data,
> > - unsigned int len, sha1_transform_fn *sha1_xform)
> > + unsigned int len, sha1_block_fn *sha1_xform)
> > {
> > struct sha1_state *sctx = shash_desc_ctx(desc);
> >
> > @@ -39,48 +36,44 @@ static int sha1_update(struct shash_desc *desc, const u8 *data,
> > (sctx->count % SHA1_BLOCK_SIZE) + len < SHA1_BLOCK_SIZE)
> > return crypto_sha1_update(desc, data, len);
> >
> > - /* make sure casting to sha1_block_fn() is safe */
> > + /* make sure sha1_block_fn() use in generic routines is safe */
> > BUILD_BUG_ON(offsetof(struct sha1_state, state) != 0);
>
> This update to the comment makes no sense, since sha1_block_fn() is obviously
> safe in the helpers, and this says nothing about the assembly functions.
> Instead this should say something like:
>
> /*
> * Make sure that struct sha1_state begins directly with the 160-bit
> * SHA1 internal state, as this is what the assembly functions expect.
> */
>
> Likewise for SHA-256 and SHA-512, except for those it would be a 256-bit and
> 512-bit internal state respectively.
Thanks! Agreed, that is much clearer.
> > -asmlinkage void sha1_transform_ssse3(u32 *digest, const char *data,
> > - unsigned int rounds);
> > +asmlinkage void sha1_transform_ssse3(struct sha1_state *digest,
> > + u8 const *data, int rounds);
>
> 'u8 const' is unconventional. Please use 'const u8' instead.
Yeah, I noticed that but decided to disrupt less. Fixed now.
> Also, this function prototype is also given in a comment in the corresponding
> assembly file. Can you please update that too, and also leave a comment in the
> assembly file like "struct sha1_state is assumed to begin with u32 state[5]."?
>
> Likewise for all the other SHA-1, and SHA-256, and SHA-512 assembly functions,
> except it would be u32 state[8] for SHA-256 and u64 state[8] for SHA-512.
I love how each uses an entirely different comment style. :) Updated!
--
Kees Cook
prev parent reply other threads:[~2019-11-21 23:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-13 18:25 [PATCH v5 0/8] crypto: x86: Fix indirect function call casts Kees Cook
2019-11-13 18:25 ` [PATCH v5 1/8] crypto: x86/glue_helper: Regularize function prototypes Kees Cook
2019-11-13 18:25 ` [PATCH v5 2/8] crypto: x86/serpent: Remove glue function macros usage Kees Cook
2019-11-13 19:34 ` Eric Biggers
2019-11-21 22:45 ` Kees Cook
2019-11-13 18:25 ` [PATCH v5 3/8] crypto: x86/camellia: Remove glue function macro usage Kees Cook
2019-11-13 19:39 ` Eric Biggers
2019-11-21 22:56 ` Kees Cook
2019-11-13 18:25 ` [PATCH v5 4/8] crypto: x86/twofish: " Kees Cook
2019-11-13 18:25 ` [PATCH v5 5/8] crypto: x86/cast6: " Kees Cook
2019-11-13 18:25 ` [PATCH v5 6/8] crypto: x86/aesni: " Kees Cook
2019-11-13 19:32 ` Eric Biggers
2019-11-13 18:25 ` [PATCH v5 7/8] crypto: x86/glue_helper: Remove function prototype cast helpers Kees Cook
2019-11-13 18:25 ` [PATCH v5 8/8] crypto, x86/sha: Eliminate casts on asm implementations Kees Cook
2019-11-13 19:55 ` Eric Biggers
2019-11-21 23:14 ` Kees Cook [this message]
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=201911211512.6A86399@keescook \
--to=keescook@chromium.org \
--cc=ard.biesheuvel@linaro.org \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=joao.moreira@intel.com \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=samitolvanen@google.com \
--cc=smueller@chronox.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;
as well as URLs for NNTP newsgroup(s).