I just ran into an issue where I had about 30 guests get duplicate mac addresses assigned. These were scattered across 30 different machines. Some debugging revealed that: 1) All the host machines were restarted within a couple seconds of each other 2) All the host machines had fairly similar libvirtd pids (within ~100 PIDs of each other) 3) Libvirt seeds the RNG using 'time(NULL) ^ getpid()' This perfectly explains why I saw so many duplicate mac addresses. Why is the RNG seed such a predictable value? Surely there has to be a better source of a random seed then the timestamp and the pid? The PID seems to me to be a very bad source of any randomness. I just ran a test across 60 of our hosts. 43 of them shared their PID with at least one other machine.
Daniel P. Berrange
2014-Nov-04 08:18 UTC
Re: [libvirt-users] virRandomBits - not very random
On Mon, Nov 03, 2014 at 11:09:12AM -0500, Brian Rak wrote:> I just ran into an issue where I had about 30 guests get duplicate mac > addresses assigned. These were scattered across 30 different machines. > > Some debugging revealed that: > > 1) All the host machines were restarted within a couple seconds of each > other > 2) All the host machines had fairly similar libvirtd pids (within ~100 PIDs > of each other) > 3) Libvirt seeds the RNG using 'time(NULL) ^ getpid()' > > This perfectly explains why I saw so many duplicate mac addresses. > > Why is the RNG seed such a predictable value? Surely there has to be a > better source of a random seed then the timestamp and the pid? > > The PID seems to me to be a very bad source of any randomness. I just ran a > test across 60 of our hosts. 43 of them shared their PID with at least one > other machine.We should probably seed it with data from /dev/urandom, and/or the new Linux getrandom() syscall (or BSD equivalent). Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Reviving an ancient thread: On 11/04/2014 02:18 AM, Daniel P. Berrange wrote:> On Mon, Nov 03, 2014 at 11:09:12AM -0500, Brian Rak wrote: >> I just ran into an issue where I had about 30 guests get duplicate mac >> addresses assigned. These were scattered across 30 different machines. >> >> Some debugging revealed that: >> >> 1) All the host machines were restarted within a couple seconds of each >> other >> 2) All the host machines had fairly similar libvirtd pids (within ~100 PIDs >> of each other) >> 3) Libvirt seeds the RNG using 'time(NULL) ^ getpid()' >> >> This perfectly explains why I saw so many duplicate mac addresses. >> >> Why is the RNG seed such a predictable value? Surely there has to be a >> better source of a random seed then the timestamp and the pid? >> >> The PID seems to me to be a very bad source of any randomness. I just ran a >> test across 60 of our hosts. 43 of them shared their PID with at least one >> other machine. > > We should probably seed it with data from /dev/urandom, and/or the new > Linux getrandom() syscall (or BSD equivalent).Did anyone ever open a BZ to track this? As far as I can tell, we still have a very predictable (meaning bad) seeding algorithm that permits large clusters to create collisions when their random number sequences sync up. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org