Skip to contentSkip to conversation

crypto: arm64/aes - do not call crypto_unregister_skcipher twice on error

PATCH Superseded Corentin Labbe 3 participants 4 messages Nov 22, 2017 – Nov 24, 2017

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: arm64/aes - do not call crypto_unregister_skcipher twice on error

When a cipher fail to register in aes_init(), the error path go thought aes_exit() then crypto_unregister_skciphers().
Since aes_exit calls also crypto_unregister_skcipher, this trigger a
refcount_t: underflow; use-after-free.

---
 arch/arm64/crypto/aes-glue.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm64/crypto/aes-glue.c +4 -1
index 998ba519a026..9e42ec96243e 100644
@@ -664,7 +664,10 @@ static int __init aes_init(void)
 	return 0;
 
 unregister_simds:
-	aes_exit();
+	for (i = 0; i < ARRAY_SIZE(aes_simd_algs); i++)
+		if (aes_simd_algs[i])
+			simd_skcipher_free(aes_simd_algs[i]);
+	crypto_unregister_shashes(mac_algs, ARRAY_SIZE(mac_algs));
 unregister_ciphers:
 	crypto_unregister_skciphers(aes_algs, ARRAY_SIZE(aes_algs));
 	return err;
Signature · 1 line
2.13.6
#1 lore raw

Hello Corentin,

Quoted 1 line · Corentin Labbe

When a cipher fail

fails

Quoted 1 line

to register in aes_init(), the error path go thought

goes through

Quoted 2 lines

aes_exit() then crypto_unregister_skciphers().
Since aes_exit calls also crypto_unregister_skcipher, this trigger a

triggers

Quoted 24 lines

refcount_t: underflow; use-after-free.

---
 arch/arm64/crypto/aes-glue.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm64/crypto/aes-glue.c +4 -2
index 998ba519a026..9e42ec96243e 100644
@@ -664,7 +664,10 @@ static int __init aes_init(void)
        return 0;
 
 unregister_simds:
-       aes_exit();
+       for (i = 0; i < ARRAY_SIZE(aes_simd_algs); i++)
+               if (aes_simd_algs[i])
+                       simd_skcipher_free(aes_simd_algs[i]);
+       crypto_unregister_shashes(mac_algs, ARRAY_SIZE(mac_algs));
 unregister_ciphers:
        crypto_unregister_skciphers(aes_algs, ARRAY_SIZE(aes_algs));
        return err;
--
Quoted 3 lines

2.13.6

Would this also fix it?

arch/arm64/crypto/aes-glue.c +1 -0
index 998ba519a026..2fa850e86aa8 100644
@@ -665,6 +665,7 @@ static int __init aes_init(void)
 
 unregister_simds:
        aes_exit();
+       return err;
 unregister_ciphers:
        crypto_unregister_skciphers(aes_algs, ARRAY_SIZE(aes_algs));
        return err;
maintainer
#2 lore raw
Quoted 2 lines · Ard Biesheuvel

Would this also fix it?

Looks good. Could you resubmit with a sign-off?

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#3 lore raw
In reply to Ard Biesheuvel
Quoted 52 lines · Ard Biesheuvel

Hello Corentin,

Quoted 1 line · Corentin Labbe

When a cipher fail

fails

Quoted 1 line

to register in aes_init(), the error path go thought

goes through

Quoted 2 lines

aes_exit() then crypto_unregister_skciphers().
Since aes_exit calls also crypto_unregister_skcipher, this trigger a

triggers

Quoted 24 lines

refcount_t: underflow; use-after-free.

---
 arch/arm64/crypto/aes-glue.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm64/crypto/aes-glue.c +4 -2
index 998ba519a026..9e42ec96243e 100644
@@ -664,7 +664,10 @@ static int __init aes_init(void)
        return 0;
 
 unregister_simds:
-       aes_exit();
+       for (i = 0; i < ARRAY_SIZE(aes_simd_algs); i++)
+               if (aes_simd_algs[i])
+                       simd_skcipher_free(aes_simd_algs[i]);
+       crypto_unregister_shashes(mac_algs, ARRAY_SIZE(mac_algs));
 unregister_ciphers:
        crypto_unregister_skciphers(aes_algs, ARRAY_SIZE(aes_algs));
        return err;
--
Quoted 3 lines

2.13.6

Would this also fix it?

arch/arm64/crypto/aes-glue.c +0 -0
index 998ba519a026..2fa850e86aa8 100644

arch/arm64/crypto/aes-glue.c static int __init aes_init(void) · line 671

Quoted 7 lines
arch/arm64/crypto/aes-glue.c +1 -0
@@ -665,6 +665,7 @@ static int __init aes_init(void)
 
 unregister_simds:
        aes_exit();
+       return err;
 unregister_ciphers:
        crypto_unregister_skciphers(aes_algs, ARRAY_SIZE(aes_algs));
        return err;

Yes it is better.

I will send a v2 today.

Regards