Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936522AbcJQRRv (ORCPT ); Mon, 17 Oct 2016 13:17:51 -0400 Received: from mail.eperm.de ([89.247.134.16]:53580 "EHLO mail.eperm.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935881AbcJQRRi (ORCPT ); Mon, 17 Oct 2016 13:17:38 -0400 From: Stephan Mueller To: Andy Lutomirski Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Matt Mackall , Herbert Xu , Rusty Russell , Jens Axboe , Matt Mullins Subject: Re: [PATCH resend 4.9] hw_random: Don't use a stack buffer in add_early_randomness() Date: Mon, 17 Oct 2016 19:17:31 +0200 Message-ID: <2711337.nAU4qxUyQs@tauon.atsec.com> User-Agent: KMail/5.3.1 (Linux/4.7.4-200.fc24.x86_64; KDE/5.26.0; x86_64; ; ) In-Reply-To: <4169224b6858d1cf149f1a73f8a03603fa19076d.1476638125.git.luto@kernel.org> References: <4169224b6858d1cf149f1a73f8a03603fa19076d.1476638125.git.luto@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 937 Lines: 30 Am Montag, 17. Oktober 2016, 10:06:27 CEST schrieb Andy Lutomirski: Hi Andy, > diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c > index 9203f2d130c0..340f96e44642 100644 > --- a/drivers/char/hw_random/core.c > +++ b/drivers/char/hw_random/core.c > @@ -84,14 +84,14 @@ static size_t rng_buffer_size(void) > > static void add_early_randomness(struct hwrng *rng) > { > - unsigned char bytes[16]; > int bytes_read; > + size_t size = min_t(size_t, 16, rng_buffer_size()); > > mutex_lock(&reading_mutex); > - bytes_read = rng_get_data(rng, bytes, sizeof(bytes), 1); > + bytes_read = rng_get_data(rng, rng_buffer, size, 1); > mutex_unlock(&reading_mutex); > if (bytes_read > 0) > - add_device_randomness(bytes, bytes_read); > + add_device_randomness(rng_buffer, bytes_read); Shouldn't there be a memset(0) of the rng_buffer at this point to avoid having such data lingering in memory? Ciao Stephan