]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
block/keyslot-manager: prevent crash when num_slots=1
authorEric Biggers <ebiggers@google.com>
Wed, 11 Nov 2020 21:48:55 +0000 (13:48 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 2 Dec 2020 07:51:55 +0000 (08:51 +0100)
commit788d34df99ad68539f9985e7bb7a4961963416e4
tree71e3128fddc6231f533be4be7eee31a66e1a322c
parent4555f3dadc4de58f19795b8c55f9a2f8873523f0
block/keyslot-manager: prevent crash when num_slots=1

[ Upstream commit 47a846536e1bf62626f1c0d8488f3718ce5f8296 ]

If there is only one keyslot, then blk_ksm_init() computes
slot_hashtable_size=1 and log_slot_ht_size=0.  This causes
blk_ksm_find_keyslot() to crash later because it uses
hash_ptr(key, log_slot_ht_size) to find the hash bucket containing the
key, and hash_ptr() doesn't support the bits == 0 case.

Fix this by making the hash table always have at least 2 buckets.

Tested by running:

    kvm-xfstests -c ext4 -g encrypt -m inlinecrypt \
                 -o blk-crypto-fallback.num_keyslots=1

Fixes: 1b2628397058 ("block: Keyslot Manager for Inline Encryption")
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
block/keyslot-manager.c