Subject: CVE-2021-46968: s390/zcrypt: fix zcard and zqueue hot-unplug memleak

From: Greg Kroah-Hartman <[email-masked]>

Description
===========

In the Linux kernel, the following vulnerability has been resolved:

s390/zcrypt: fix zcard and zqueue hot-unplug memleak

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.

The Linux kernel CVE team has assigned CVE-2021-46968 to this issue.

Affected and fixed versions
===========================

	Issue introduced in 5.10 with commit 29c2680fd2bf and fixed in 5.10.36 with commit 026499a9c2e0
	Issue introduced in 5.10 with commit 29c2680fd2bf and fixed in 5.11.20 with commit 055a063a18bc
	Issue introduced in 5.10 with commit 29c2680fd2bf and fixed in 5.12.3 with commit 971dc8706cee
	Issue introduced in 5.10 with commit 29c2680fd2bf and fixed in 5.13 with commit 70fac8088cfa

Please see https://www.kernel.org for a full list of currently supported
kernel versions by the kernel community.

Unaffected versions might change over time as fixes are backported to
older supported kernel versions.  The official CVE entry at
	https://cve.org/CVERecord/?id=CVE-2021-46968
will be updated if fixes are backported, please check that for the most
up to date information about this issue.

Affected files
==============

The file(s) affected by this issue are:
	drivers/s390/crypto/zcrypt_card.c
	drivers/s390/crypto/zcrypt_queue.c

Mitigation
==========

The Linux kernel CVE team recommends that you update to the latest
stable kernel version for this, and many other bugfixes.  Individual
changes are never tested alone, but rather are part of a larger kernel
release.  Cherry-picking individual commits is not recommended or
supported by the Linux kernel community at all.  If however, updating to
the latest release is impossible, the individual changes to resolve this
issue can be found at these commits:
	https://git.kernel.org/stable/c/026499a9c2e002e621ad568d1378324ae97e5524
	https://git.kernel.org/stable/c/055a063a18bcd19b93709e3eac8078d6b2f04599
	https://git.kernel.org/stable/c/971dc8706cee47393d393905d294ea47e39503d3
	https://git.kernel.org/stable/c/70fac8088cfad9f3b379c9082832b4d7532c16c2