mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Aaron Straus <aaron@merfinllc.com>
Cc: mpm@selenic.com, linux-kernel@vger.kernel.org, tytso@mit.edu,
	stable@kernel.org
Subject: Re: drivers/char/random.c line 728 BUG
Date: Fri, 29 Aug 2008 15:42:15 -0700	[thread overview]
Message-ID: <20080829154215.970fd4c1.akpm@linux-foundation.org> (raw)
In-Reply-To: <20080829223155.GM31108@merfinllc.com>

On Fri, 29 Aug 2008 15:31:55 -0700
Aaron Straus <aaron@merfinllc.com> wrote:

> > -	if (r == &input_pool &&
> > -	    r->entropy_count >= random_read_wakeup_thresh) {
> > +	if (r == &input_pool && entropy_count >= random_read_wakeup_thresh) {
> >  		wake_up_interruptible(&random_read_wait);
> >  		kill_fasync(&fasync, SIGIO, POLL_IN);
> >  	}
> > -
> > +	r->entropy_count = entropy_count;
> 
> Here you set the entropy_count in the pool *after* waking up the reader.
> I was a little worried the reader would find the entropy_count unchanged
> and go back to sleep.
> 

Probably it doesn't matter because of the coverage of the lock but yes,
let's do the assignment first.

--- a/drivers/char/random.c~drivers-char-randomc-fix-a-race-which-can-lead-to-a-bogus-bug-fix-fix
+++ a/drivers/char/random.c
@@ -535,13 +535,13 @@ static void credit_entropy_bits(struct e
 		entropy_count = 0;
 	} else if (entropy_count > r->poolinfo->POOLBITS)
 		entropy_count = r->poolinfo->POOLBITS;
+	r->entropy_count = entropy_count;
 
 	/* should we wake readers? */
 	if (r == &input_pool && entropy_count >= random_read_wakeup_thresh) {
 		wake_up_interruptible(&random_read_wait);
 		kill_fasync(&fasync, SIGIO, POLL_IN);
 	}
-	r->entropy_count = entropy_count;
 	spin_unlock_irqrestore(&r->lock, flags);
 }
 
_


  reply	other threads:[~2008-08-29 22:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-26 22:59 Aaron Straus
2008-08-28 22:59 ` Aaron Straus
2008-08-29 19:48   ` Andrew Morton
2008-08-29 19:54     ` Andrew Morton
2008-08-29 22:31     ` Aaron Straus
2008-08-29 22:42       ` Andrew Morton [this message]
2008-09-03 18:18     ` Matt Mackall
2008-09-03 18:28       ` Aaron Straus
2008-09-03 22:12         ` Matt Mackall
2008-09-03 22:32           ` Andrew Morton
2008-09-03 22:51             ` Matt Mackall
2008-09-03 23:12               ` Andrew Morton

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=20080829154215.970fd4c1.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=aaron@merfinllc.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpm@selenic.com \
    --cc=stable@kernel.org \
    --cc=tytso@mit.edu \
    /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

Powered by JetHome