s390/zcrypt: fix zcard and zqueue hot-unplug memleak
authorHarald Freudenberger <freude@linux.ibm.com>
Thu, 15 Apr 2021 09:22:03 +0000 (11:22 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 11 May 2021 12:47:11 +0000 (14:47 +0200)
commit026499a9c2e002e621ad568d1378324ae97e5524
tree12b003303fc770f15e0092ad7dceaa1d0ee8dbdc
parente534a4b139a82f91b61f8c9c084b9f681473d354
s390/zcrypt: fix zcard and zqueue hot-unplug memleak

commit 70fac8088cfad9f3b379c9082832b4d7532c16c2 upstream.

Tests with kvm and a kmemdebug kernel showed, that on hot unplug the
zcard and zqueue structs for the unplugged card or queue are not
properly freed because of a mismatch with get/put for the embedded
kref counter.

This fix now adjusts the handling of the kref counters. With init the
kref counter starts with 1. This initial value needs to drop to zero
with the unregister of the card or queue to trigger the release and
free the object.

Fixes: 29c2680fd2bf ("s390/ap: fix ap devices reference counting")
Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Cc: stable@vger.kernel.org
Reviewed-by: Julian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/s390/crypto/zcrypt_card.c
drivers/s390/crypto/zcrypt_queue.c