Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	linux-hardening@vger.kernel.org,
	Edward Adam Davis <eadavis@qq.com>,
	syzbot+e8bcd7ee3db6cb5cb875@syzkaller.appspotmail.com,
	davem@davemloft.net, linux-crypto@vger.kernel.org,
	linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Re: [PATCH] crypto: Prevent kernel-infoleak in rng_recvmsg
Date: Tue, 26 Aug 2025 09:58:36 -0700	[thread overview]
Message-ID: <202508260957.6D8C43E2@keescook> (raw)
In-Reply-To: <CAMj1kXF4aRL02CKnO5T9kKnvSV=BcMDiD=mDW7CKQx5t_HmaHw@mail.gmail.com>

On Tue, Aug 26, 2025 at 03:51:04PM +0200, Ard Biesheuvel wrote:
> (cc Kees)
> 
> On Sat, 16 Aug 2025 at 11:17, Herbert Xu <herbert@gondor.apana.org.au> wrote:
> >
> > On Sat, Aug 09, 2025 at 05:59:43PM +0800, Edward Adam Davis wrote:
> > > Initialize the intermediary array member to 0 to prevent the kernel from
> > > leaking uninitialized data to user space.
> > >
> > > Reported-by: syzbot+e8bcd7ee3db6cb5cb875@syzkaller.appspotmail.com
> > > Closes: https://syzkaller.appspot.com/bug?extid=e8bcd7ee3db6cb5cb875
> > > Tested-by: syzbot+e8bcd7ee3db6cb5cb875@syzkaller.appspotmail.com
> > > Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> > > ---
> > >  crypto/jitterentropy-kcapi.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/crypto/jitterentropy-kcapi.c b/crypto/jitterentropy-kcapi.c
> > > index c24d4ff2b4a8..9e9e069f55af 100644
> > > --- a/crypto/jitterentropy-kcapi.c
> > > +++ b/crypto/jitterentropy-kcapi.c
> > > @@ -107,7 +107,7 @@ int jent_hash_time(void *hash_state, __u64 time, u8 *addtl,
> > >  {
> > >       struct shash_desc *hash_state_desc = (struct shash_desc *)hash_state;
> > >       SHASH_DESC_ON_STACK(desc, hash_state_desc->tfm);
> > > -     u8 intermediary[SHA3_256_DIGEST_SIZE];
> > > +     u8 intermediary[SHA3_256_DIGEST_SIZE] = { 0 };
> >
> > This is not a leak! The stack memroy is hashed and fed into the
> > entropy pool.
> 
> Is there still a point to doing this now that the compiler
> zero-initializes automatic variables? Or does that not apply to u8
> arrays? (asking Kees)

Wait, the jitterentropy _depends_ on "uninitialized" stack contents?
That is not a safe way to get entropy (especially since the stack
contents are likely predictable). But regardless, yes, arrays would be
fully wiped by zero-initialized automatic variables.

To force it to be uninit, use __uninitialized.

-- 
Kees Cook

      reply	other threads:[~2025-08-26 16:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-08  8:07 [syzbot] [crypto?] KMSAN: kernel-infoleak in rng_recvmsg syzbot
2025-08-09  9:59 ` [PATCH] crypto: Prevent " Edward Adam Davis
2025-08-16  9:17   ` Herbert Xu
2025-08-17  8:51     ` Herbert Xu
2025-08-17 10:59       ` [PATCH V2] crypto: Mark intermediary memory as clean Edward Adam Davis
2025-08-17 11:40         ` Herbert Xu
2025-08-18 12:17           ` Edward Adam Davis
2025-08-18 12:30             ` Herbert Xu
2025-08-18 12:43               ` Edward Adam Davis
2025-08-18 13:13                 ` Stephan Mueller
2025-08-18 13:24                   ` [PATCH V3] " Edward Adam Davis
2025-08-18 13:32                     ` Stephan Mueller
2025-08-30  8:45                     ` Herbert Xu
2025-08-26 13:51     ` [PATCH] crypto: Prevent kernel-infoleak in rng_recvmsg Ard Biesheuvel
2025-08-26 16:58       ` 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=202508260957.6D8C43E2@keescook \
    --to=kees@kernel.org \
    --cc=ardb@kernel.org \
    --cc=davem@davemloft.net \
    --cc=eadavis@qq.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+e8bcd7ee3db6cb5cb875@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox