Skip to contentSkip to conversation

double unlock in rng_dev_read()

DISCUSSION Dan Carpenter 2 participants 5 messages Dec 23, 2009 – Dec 24, 2009 Hardware random number generator core

lore
Share & tools
lore
#0 lore raw

It seems like we unlock rng_mutex twice (2.6.33-rc1).

drivers/char/hw_random/core.c
151 mutex_unlock(&rng_mutex);
152
153 if (need_resched())
154 schedule_timeout_interruptible(1);
155
156 if (signal_pending(current)) {
157 err = -ERESTARTSYS;
158 goto out;
159 }
160 }
161 out_unlock:
162 mutex_unlock(&rng_mutex);

regards,
dan carpenter

maintainer
#1 lore raw
Quoted 15 lines · Dan Carpenter

It seems like we unlock rng_mutex twice (2.6.33-rc1).

drivers/char/hw_random/core.c

   151                  mutex_unlock(&rng_mutex);
   152
   153                  if (need_resched())
   154                          schedule_timeout_interruptible(1);
   155
   156                  if (signal_pending(current)) {
   157                          err = -ERESTARTSYS;
   158                          goto out;
   159                  }
   160          }
   161  out_unlock:
   162          mutex_unlock(&rng_mutex);

Hmm, are you sure you didn't mistake out for out_unlock? :)

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#2 lore raw
Quoted 17 lines · Herbert Xu
Quoted 15 lines · Dan Carpenter

It seems like we unlock rng_mutex twice (2.6.33-rc1).

drivers/char/hw_random/core.c

   151                  mutex_unlock(&rng_mutex);
   152
   153                  if (need_resched())
   154                          schedule_timeout_interruptible(1);
   155
   156                  if (signal_pending(current)) {
   157                          err = -ERESTARTSYS;
   158                          goto out;
   159                  }
   160          }
   161  out_unlock:
   162          mutex_unlock(&rng_mutex);
Quoted 1 line

Hmm, are you sure you didn't mistake out for out_unlock? :)

No no. I mean when size hits zero we are rng_mutex is unlocked.

regards,
dan carpenter

Quoted 5 lines
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer
#3 lore raw
Quoted 2 lines · Dan Carpenter

No no. I mean when size hits zero we are rng_mutex is unlocked.

Good catch! I'll add this patch to the tree. Please take a look at it. Thanks!

commit f5908267b67917b8cbd98b27fd2be9b5f62ec76f

Author: Herbert Xu <[email protected]>
Date:   Wed Dec 23 23:22:34 2009 +0800

hwrng: core - Fix double unlock in rng_dev_read

When the loop terminates with size == 0 in rng_dev_read we will unlock the rng mutex twice.

drivers/char/hw_random/core.c +3 -3
index e989f67..3d9c61e 100644
@@ -158,10 +158,11 @@ static ssize_t rng_dev_read(struct file *filp, char __user *buf,
 			goto out;
 		}
 	}
-out_unlock:
-	mutex_unlock(&rng_mutex);
 out:
 	return ret ? : err;
+out_unlock:
+	mutex_unlock(&rng_mutex);
+	goto out;
 }
 
-- 

Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

author Acked-by
#4 lore raw
Quoted 7 lines · Herbert Xu
Quoted 2 lines · Dan Carpenter

No no. I mean when size hits zero we are rng_mutex is unlocked.

Good catch! I'll add this patch to the tree. Please take a look at it. Thanks!

Great.

regards,
dan carpenter

Quoted 34 lines

commit f5908267b67917b8cbd98b27fd2be9b5f62ec76f

Author: Herbert Xu <[email protected]>
Date:   Wed Dec 23 23:22:34 2009 +0800

hwrng: core - Fix double unlock in rng_dev_read

When the loop terminates with size == 0 in rng_dev_read we will unlock the rng mutex twice.

drivers/char/hw_random/core.c +3 -3
index e989f67..3d9c61e 100644
@@ -158,10 +158,11 @@ static ssize_t rng_dev_read(struct file *filp, char __user *buf,
 			goto out;
 		}
 	}
-out_unlock:
-	mutex_unlock(&rng_mutex);
 out:
 	return ret ? : err;
+out_unlock:
+	mutex_unlock(&rng_mutex);
+	goto out;
 }
 
-- 

Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt