Keys: Fix key serial number collision handling
authorDavid Howells <dhowells@redhat.com>
Fri, 9 Feb 2007 14:30:37 +0000 (09:30 -0500)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 9 Mar 2007 18:50:18 +0000 (10:50 -0800)
commitdbd60d51abaf4c31f4c4b5e521745af301535447
tree5d98a414210c937f8b0892a84cad4b0c8ad22e7f
parentb3725e12ab2cf9e0f1254506baef3f9206520d3e
Keys: Fix key serial number collision handling

Fix the key serial number collision avoidance code in key_alloc_serial().

This didn't use to be so much of a problem as the key serial numbers were
allocated from a simple incremental counter, and it would have to go through
two billion keys before it could possibly encounter a collision.  However, now
that random numbers are used instead, collisions are much more likely.

This is fixed by finding a hole in the rbtree where the next unused serial
number ought to be and using that by going almost back to the top of the
insertion routine and redoing the insertion with the new serial number rather
than trying to be clever and attempting to work out the insertion point
pointer directly.

This fixes kernel BZ #7727.

Signed-off-by: David Howells <dhowells@redhat.com>
Cc: Chuck Ebbert <cebbert@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
security/keys/key.c