All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org
Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
	Harald Freudenberger <freude@linux.ibm.com>,
	Holger Dengler <dengler@linux.ibm.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	Joerg Schmidbauer <jschmidb@de.ibm.com>,
	Ard Biesheuvel <ardb@kernel.org>,
	"Jason A . Donenfeld" <Jason@zx2c4.com>,
	stable@vger.kernel.org, Ingo Franzki <ifranzki@linux.ibm.com>
Subject: Re: [PATCH] crypto: s390/sha - Fix uninitialized variable in SHA-1 and SHA-2
Date: Mon, 30 Jun 2025 10:02:45 -0700	[thread overview]
Message-ID: <20250630170245.GD1220@sol> (raw)
In-Reply-To: <20250630165805.GC1220@sol>

On Mon, Jun 30, 2025 at 09:58:05AM -0700, Eric Biggers wrote:
> On Fri, Jun 27, 2025 at 11:56:49AM -0700, Eric Biggers wrote:
> > Commit 88c02b3f79a6 ("s390/sha3: Support sha3 performance enhancements")
> > added the field s390_sha_ctx::first_message_part and made it be used by
> > s390_sha_update_blocks().  At the time, s390_sha_update_blocks() was
> > used by all the s390 SHA-1, SHA-2, and SHA-3 algorithms.  However, only
> > the initialization functions for SHA-3 were updated, leaving SHA-1 and
> > SHA-2 using first_message_part uninitialized.
> > 
> > This could cause e.g. CPACF_KIMD_SHA_512 | CPACF_KIMD_NIP to be used
> > instead of just CPACF_KIMD_NIP.  It's unclear why this didn't cause a
> > problem earlier; this bug was found only when UBSAN detected the
> > uninitialized boolean.  Perhaps the CPU ignores CPACF_KIMD_NIP for SHA-1
> > and SHA-2.  Regardless, let's fix this.  For now just initialize to
> > false, i.e. don't try to "optimize" the SHA state initialization.
> > 
> > Note: in 6.16, we need to patch SHA-1, SHA-384, and SHA-512.  In 6.15
> > and earlier, we'll also need to patch SHA-224 and SHA-256, as they
> > hadn't yet been librarified (which incidentally fixed this bug).
> > 
> > Fixes: 88c02b3f79a6 ("s390/sha3: Support sha3 performance enhancements")
> > Cc: stable@vger.kernel.org
> > Reported-by: Ingo Franzki <ifranzki@linux.ibm.com>
> > Closes: https://lore.kernel.org/r/12740696-595c-4604-873e-aefe8b405fbf@linux.ibm.com
> > Signed-off-by: Eric Biggers <ebiggers@kernel.org>
> > ---
> > 
> > This is targeting 6.16.  I'd prefer to take this through
> > libcrypto-fixes, since the librarification work is also touching this
> > area.  But let me know if there's a preference for the crypto tree or
> > the s390 tree instead.
> 
> Applied to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-fixes

Forgot to mention: I revised the first two paragraphs of the commit message to
fix a couple things and clarify that the accidental CPACF_KIMD_NIP was indeed
ignored (as per Ingo):

    crypto: s390/sha - Fix uninitialized variable in SHA-1 and SHA-2
    
    Commit 88c02b3f79a6 ("s390/sha3: Support sha3 performance enhancements")
    added the field s390_sha_ctx::first_message_part and made it be used by
    s390_sha_update() (now s390_sha_update_blocks()).  At the time,
    s390_sha_update() was used by all the s390 SHA-1, SHA-2, and SHA-3
    algorithms.  However, only the initialization functions for SHA-3 were
    updated, leaving SHA-1 and SHA-2 using first_message_part uninitialized.
    
    This could cause e.g. the function code CPACF_KIMD_SHA_512 |
    CPACF_KIMD_NIP to be used instead of just CPACF_KIMD_SHA_512.  This
    apparently was harmless, as the SHA-1 and SHA-2 function codes ignore
    CPACF_KIMD_NIP; it is recognized only by the SHA-3 function codes
    (https://lore.kernel.org/r/73477fe9-a1dc-4e38-98a6-eba9921e8afa@linux.ibm.com/).
    Therefore, this bug was found only when first_message_part was later
    converted to a boolean and UBSAN detected its uninitialized use.
    Regardless, let's fix this by just initializing to false.
    
    Note: in 6.16, we need to patch SHA-1, SHA-384, and SHA-512.  In 6.15
    and earlier, we'll also need to patch SHA-224 and SHA-256, as they
    hadn't yet been librarified (which incidentally fixed this bug).
    
    Fixes: 88c02b3f79a6 ("s390/sha3: Support sha3 performance enhancements")
    Cc: stable@vger.kernel.org
    Reported-by: Ingo Franzki <ifranzki@linux.ibm.com>
    Closes: https://lore.kernel.org/r/12740696-595c-4604-873e-aefe8b405fbf@linux.ibm.com
    Acked-by: Heiko Carstens <hca@linux.ibm.com>
    Reviewed-by: Ingo Franzki <ifranzki@linux.ibm.com>
    Link: https://lore.kernel.org/r/20250627185649.35321-1-ebiggers@kernel.org
    Signed-off-by: Eric Biggers <ebiggers@kernel.org>

  reply	other threads:[~2025-06-30 17:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-27 18:56 [PATCH] crypto: s390/sha - Fix uninitialized variable in SHA-1 and SHA-2 Eric Biggers
2025-06-27 21:56 ` Eric Biggers
2025-06-30  6:26 ` Ingo Franzki
2025-06-30 16:57   ` Eric Biggers
2025-06-30  7:36 ` Heiko Carstens
2025-06-30 16:58 ` Eric Biggers
2025-06-30 17:02   ` Eric Biggers [this message]
2025-07-03 17:20 ` Eric Biggers
2025-07-07  6:47   ` Ingo Franzki

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=20250630170245.GD1220@sol \
    --to=ebiggers@kernel.org \
    --cc=Jason@zx2c4.com \
    --cc=agordeev@linux.ibm.com \
    --cc=ardb@kernel.org \
    --cc=borntraeger@linux.ibm.com \
    --cc=dengler@linux.ibm.com \
    --cc=freude@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=ifranzki@linux.ibm.com \
    --cc=jschmidb@de.ibm.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=svens@linux.ibm.com \
    /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.