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] [day] [month] [year] [list]
Date:	Thu, 12 Feb 2009 00:27:22 +1100
From:	Herbert Xu <herbert@...dor.apana.org.au>
To:	Alexander Clouter <alex@...riz.org.uk>
Cc:	linux-kernel@...r.kernel.org, akpm@...ux-foundation.org
Subject: Re: [PATCHv2] hw_random: add timeriomem-rng driver

On Tue, Feb 10, 2009 at 07:39:04PM +0000, Alexander Clouter wrote:
>
> My original code[1] approach, with timer_pending() in there, would have 
> been okay then, right?
> ----
> if (timer_pending(&timeriomem_rng_timer)) {
>   if (!wait)
>     return 0;
> 
>   del_timer_sync(&timeriomem_rng_timer);
>   delay = timeriomem_rng_timer.expires - jiffies;
> 
>   schedule_timeout_uninterruptible(delay);
> }

Yes probably but it is racy.  Also it's better if we can avoid
the expires - jiffies calculation if only because then we won't
have to tell Andrew why it can't be negative :)

> > Instead of deleting the timer above, why not create a rng->present
> > variable which you set to zero here, and the timer sets it to
> > non-zero.  Then you just need to return rng->present in your
> > data_present function.
>
> Sounds fair, better than the timer_pending approach and easier to 
> understand.

Oh I forgot about the blocking case.  We can probably add a
completion object to handle that.  So something like

	if (!wait || rng->present)
		return rng->present;

	wait_for_completion(&rng->completion);
	return 1;

The timer would do

	rng->present = 1;
	complete(&rng->completion);

And the reader would do

	rng->present = 0;
	INIT_COMPLETION(rng->completion);
	add_timer(...)

Note that everything but the timer is completely serialised by
the hwrng mutex so we only need to worry about racing against
the timer.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@...dor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ