提交 d116bcc0 编写于 作者: M Marek Vasut 提交者: Laibin Qiu

crypto: stm32/crc32 - Fix kernel BUG triggered in probe()

stable inclusion
from linux-4.19.226
commit e670c4b7c1ca134463211b27af69695a3adcb846

--------------------------------

commit 29009604 upstream.

The include/linux/crypto.h struct crypto_alg field cra_driver_name description
states "Unique name of the transformation provider. " ... " this contains the
name of the chip or provider and the name of the transformation algorithm."

In case of the stm32-crc driver, field cra_driver_name is identical for all
registered transformation providers and set to the name of the driver itself,
which is incorrect. This patch fixes it by assigning a unique cra_driver_name
to each registered transformation provider.

The kernel crash is triggered when the driver calls crypto_register_shashes()
which calls crypto_register_shash(), which calls crypto_register_alg(), which
calls __crypto_register_alg(), which returns -EEXIST, which is propagated
back through this call chain. Upon -EEXIST from crypto_register_shash(), the
crypto_register_shashes() starts unregistering the providers back, and calls
crypto_unregister_shash(), which calls crypto_unregister_alg(), and this is
where the BUG() triggers due to incorrect cra_refcnt.

Fixes: b51dbe90 ("crypto: stm32 - Support for STM32 CRC32 crypto module")
Signed-off-by: NMarek Vasut <marex@denx.de>
Cc: <stable@vger.kernel.org> # 4.12+
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Fabien Dessenne <fabien.dessenne@st.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Lionel Debieve <lionel.debieve@st.com>
Cc: Nicolas Toromanoff <nicolas.toromanoff@st.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-stm32@st-md-mailman.stormreply.com
To: linux-crypto@vger.kernel.org
Acked-by: NNicolas Toromanoff <nicolas.toromanoff@foss.st.com>
Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NYongqiang Liu <liuyongqiang13@huawei.com>
Signed-off-by: NLaibin Qiu <qiulaibin@huawei.com>
上级 277de38d
...@@ -217,7 +217,7 @@ static struct shash_alg algs[] = { ...@@ -217,7 +217,7 @@ static struct shash_alg algs[] = {
.digestsize = CHKSUM_DIGEST_SIZE, .digestsize = CHKSUM_DIGEST_SIZE,
.base = { .base = {
.cra_name = "crc32", .cra_name = "crc32",
.cra_driver_name = DRIVER_NAME, .cra_driver_name = "stm32-crc32-crc32",
.cra_priority = 200, .cra_priority = 200,
.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, .cra_flags = CRYPTO_ALG_OPTIONAL_KEY,
.cra_blocksize = CHKSUM_BLOCK_SIZE, .cra_blocksize = CHKSUM_BLOCK_SIZE,
...@@ -239,7 +239,7 @@ static struct shash_alg algs[] = { ...@@ -239,7 +239,7 @@ static struct shash_alg algs[] = {
.digestsize = CHKSUM_DIGEST_SIZE, .digestsize = CHKSUM_DIGEST_SIZE,
.base = { .base = {
.cra_name = "crc32c", .cra_name = "crc32c",
.cra_driver_name = DRIVER_NAME, .cra_driver_name = "stm32-crc32-crc32c",
.cra_priority = 200, .cra_priority = 200,
.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, .cra_flags = CRYPTO_ALG_OPTIONAL_KEY,
.cra_blocksize = CHKSUM_BLOCK_SIZE, .cra_blocksize = CHKSUM_BLOCK_SIZE,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册