lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 12 Nov 2013 15:35:12 -0800
From:	Stephen Hemminger <stephen@...workplumber.org>
To:	Daniel Borkmann <dborkman@...hat.com>
Cc:	davem@...emloft.net, netdev@...r.kernel.org,
	Hannes Frederic Sowa <hannes@...essinduktion.org>
Subject: Re: [PATCH 2/2] random32: use msecs_to_jiffies for reseed timer

On Tue, 12 Nov 2013 23:45:42 +0100
Daniel Borkmann <dborkman@...hat.com> wrote:

> Use msecs_to_jiffies, for these calculations as different HZ
> considerations are taken into account for conversion of the timer
> shot, and also it makes the code more readable.
> 
> Signed-off-by: Daniel Borkmann <dborkman@...hat.com>
> Signed-off-by: Hannes Frederic Sowa <hannes@...essinduktion.org>
> ---
>  lib/random32.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/random32.c b/lib/random32.c
> index 4f9d5df..1e5b2df 100644
> --- a/lib/random32.c
> +++ b/lib/random32.c
> @@ -214,18 +214,22 @@ static DEFINE_TIMER(seed_timer, __prandom_timer, 0, 0);
>  static void __prandom_timer(unsigned long dontcare)
>  {
>  	u32 entropy;
> +	unsigned long expires;
>  
>  	get_random_bytes(&entropy, sizeof(entropy));
>  	prandom_seed(entropy);
> +
>  	/* reseed every ~60 seconds, in [40 .. 80) interval with slack */
> -	seed_timer.expires = jiffies + (40 * HZ + (prandom_u32() % (40 * HZ)));
> +	expires = 40 + (prandom_u32() % 40);
> +	seed_timer.expires = jiffies + msecs_to_jiffies(expires * MSEC_PER_SEC);
> +
>  	add_timer(&seed_timer);
>  }
>  
>  static void __init __prandom_start_seed_timer(void)
>  {
>  	set_timer_slack(&seed_timer, HZ);
> -	seed_timer.expires = jiffies + 40 * HZ;
> +	seed_timer.expires = jiffies + msecs_to_jiffies(40 * MSEC_PER_SEC);
>  	add_timer(&seed_timer);
>  }
>  

Some questions:
 1. What is the point of using msecs_to_jiffies? the older code already handled
    differing HZ?
 2. Why the magic 40-80 sec range? What about platforms with very low entropy
    you will end up draining it faster.
 3. I prefer using mod_timer rather than setting expires and call add_timer
 4. You should also use round_jiffies to save power by making the wakeup on a second
    boundary.

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ