From: Mathieu Desnoyers Date: Thu, 12 Apr 2012 19:49:12 +0000 (-0700) Subject: drivers/char/random.c: fix boot id uniqueness race X-Git-Tag: v3.2.29~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a457fb130726356e758eeadf230b21993986d0ab;p=profile%2Fivi%2Fkernel-adaptation-intel-automotive.git drivers/char/random.c: fix boot id uniqueness race commit 44e4360fa3384850d65dd36fb4e6e5f2f112709b upstream. /proc/sys/kernel/random/boot_id can be read concurrently by userspace processes. If two (or more) user-space processes concurrently read boot_id when sysctl_bootid is not yet assigned, a race can occur making boot_id differ between the reads. Because the whole point of the boot id is to be unique across a kernel execution, fix this by protecting this operation with a spinlock. Given that this operation is not frequently used, hitting the spinlock on each call should not be an issue. Signed-off-by: Mathieu Desnoyers Cc: "Theodore Ts'o" Cc: Matt Mackall Signed-off-by: Eric Dumazet Cc: Greg Kroah-Hartman Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Ben Hutchings --- diff --git a/drivers/char/random.c b/drivers/char/random.c index 631d4f6..918979f 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1391,10 +1391,15 @@ static int proc_do_uuid(ctl_table *table, int write, uuid = table->data; if (!uuid) { uuid = tmp_uuid; - uuid[8] = 0; - } - if (uuid[8] == 0) generate_random_uuid(uuid); + } else { + static DEFINE_SPINLOCK(bootid_spinlock); + + spin_lock(&bootid_spinlock); + if (!uuid[8]) + generate_random_uuid(uuid); + spin_unlock(&bootid_spinlock); + } sprintf(buf, "%pU", uuid);