Subject: MBR disk signature not random enough
From: Philip Rowlands <[email-masked]>
To: [email-masked]
Date: Fri, 13 Sep 2013 14:06:30 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

libparted/labels/dos.c:generate_random_id()
is used to create a new mbr_signature where none exists. The possible 
return values for generate_random_id() range from 0 to 999999, derived 
from the tv_usec field of gettimeofday(2).

This limits the actual value written to mbr_signature to 0.023% of the 
possible uint32 values.

I don't know how many MBRs in the world libparted has written the 
mbr_signature to, but the chance of collisions are greatly increased by 
having an artificially restricted value.

Is there a better libc-provided rand(3)/random(3) function which can be 
used to provide a full 32 bits of randomness?

I haven't checked all the other mklabel types, but it's possible they 
have similar limitations. gpt.c uses uuid_generate() which delegates the 
task to libuuid. Perhaps this could be used (with truncated output) for 
the MBR signature?

Cheers,
Phil