]> git.baikalelectronics.ru Git - kernel.git/commit
KEYS: Fix keyring content gc scanner
authorDavid Howells <dhowells@redhat.com>
Thu, 14 Nov 2013 13:02:31 +0000 (13:02 +0000)
committerDavid Howells <dhowells@redhat.com>
Thu, 14 Nov 2013 14:09:53 +0000 (14:09 +0000)
commit94a40edeaaf79ca1eee5d74bc081c6140292e231
treea24b4672750ceea1850f7b97131256f163554ea7
parent7e2d9d2582887e39130ff9310becaef9b22474cf
KEYS: Fix keyring content gc scanner

Key pointers stored in the keyring are marked in bit 1 to indicate if they
point to a keyring.  We need to strip off this bit before using the pointer
when iterating over the keyring for the purpose of looking for links to garbage
collect.

This means that expirable keyrings aren't correctly expiring because the
checker is seeing their key pointer with 2 added to it.

Since the fix for this involves knowing about the internals of the keyring,
key_gc_keyring() is moved to keyring.c and merged into keyring_gc().

This can be tested by:

echo 2 >/proc/sys/kernel/keys/gc_delay
keyctl timeout `keyctl add keyring qwerty "" @s` 2
cat /proc/keys
sleep 5; cat /proc/keys

which should see a keyring called "qwerty" appear in the session keyring and
then disappear after it expires, and:

echo 2 >/proc/sys/kernel/keys/gc_delay
a=`keyctl get_persistent @s`
b=`keyctl add keyring 0 "" $a`
keyctl add user a a $b
keyctl timeout $b 2
cat /proc/keys
sleep 5; cat /proc/keys

which should see a keyring called "0" with a key called "a" in it appear in the
user's persistent keyring (which will be attached to the session keyring) and
then both the "0" keyring and the "a" key should disappear when the "0" keyring
expires.

Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Simo Sorce <simo@redhat.com>
security/keys/gc.c
security/keys/keyring.c