1
0
Fork 0
alistair23-linux/security/keys/encrypted-keys
Eric Biggers 64d107d3ac KEYS: encrypted: fix race causing incorrect HMAC calculations
The encrypted-keys module was using a single global HMAC transform,
which could be rekeyed by multiple threads concurrently operating on
different keys, causing incorrect HMAC values to be calculated.  Fix
this by allocating a new HMAC transform whenever we need to calculate a
HMAC.  Also simplify things a bit by allocating the shash_desc's using
SHASH_DESC_ON_STACK() for both the HMAC and unkeyed hashes.

The following script reproduces the bug:

    keyctl new_session
    keyctl add user master "abcdefghijklmnop" @s
    for i in $(seq 2); do
        (
            set -e
            for j in $(seq 1000); do
                keyid=$(keyctl add encrypted desc$i "new user:master 25" @s)
                datablob="$(keyctl pipe $keyid)"
                keyctl unlink $keyid > /dev/null
                keyid=$(keyctl add encrypted desc$i "load $datablob" @s)
                keyctl unlink $keyid > /dev/null
            done
        ) &
    done

Output with bug:

    [  439.691094] encrypted_key: bad hmac (-22)
    add_key: Invalid argument
    add_key: Invalid argument

Cc: Mimi Zohar <zohar@linux.vnet.ibm.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <james.l.morris@oracle.com>
2017-06-09 13:29:47 +10:00
..
Makefile encrypted-keys: module build fixes 2011-11-16 14:23:14 -05:00
ecryptfs_format.c encrypted-keys: create encrypted-keys directory 2011-09-14 15:22:26 -04:00
ecryptfs_format.h encrypted-keys: create encrypted-keys directory 2011-09-14 15:22:26 -04:00
encrypted.c KEYS: encrypted: fix race causing incorrect HMAC calculations 2017-06-09 13:29:47 +10:00
encrypted.h KEYS: Merge the type-specific data with the payload data 2015-10-21 15:18:36 +01:00
masterkey_trusted.c KEYS: Merge the type-specific data with the payload data 2015-10-21 15:18:36 +01:00