Skip to contentSkip to conversation

crypto: If two strings are exact match, they must have same length.

PATCH In review Ming Ma 2 participants 3 messages Mar 21, 2017 – Mar 27, 2017 Crypto API

lore
Share & tools
lore

Ming Ma

author
#0 lore raw

PATCH 1/1 crypto: If two strings are exact match, they must have same length.

When both "crct10dif-pclmul" algorithm and "crct10dif-generic" algorithm exist in crypto_alg_list, "crct10dif-pclmul" should be selected, since it has higher priority than "crct10dif-generic". However, both algorithms have the same cra_name "crct10dif". If we use "crct10dif" to find a matched algorithm in crypto_alg_list, it's possible "crct10dif-generic" is selected, because the code calls strcmp to decide if two string are exact match, but doesn't check if two strings have the same length.

exact = !strcmp(q->cra_driver_name, name);

So ,if "crct10dif-generic" is in front of "crct10dif-pclmul" in crypto_alg_list, it will be picked as the matched algorithm, even if it has lower priority than "crct10dif-pclmul".

---
 crypto/api.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
crypto/api.c +2 -1
index b16ce16..5b3d45a 100644
@@ -76,7 +76,8 @@ static struct crypto_alg *__crypto_alg_lookup(const char *name, u32 type,
 		    ((struct crypto_larval *)q)->mask != mask)
 			continue;
 
-		exact = !strcmp(q->cra_driver_name, name);
+		exact = (strlen(name) == strlen(q->cra_driver_name)) &&
+				!strcmp(q->cra_driver_name, name);
 		fuzzy = !strcmp(q->cra_name, name);
 		if (!exact && !(fuzzy && q->cra_priority > best))
 			continue;
Signature · 1 line
2.4.11
maintainer
#1 lore raw
Quoted 23 lines · Ming Ma

When both "crct10dif-pclmul" algorithm and "crct10dif-generic" algorithm exist in crypto_alg_list, "crct10dif-pclmul" should be selected, since it has higher priority than "crct10dif-generic". However, both algorithms have the same cra_name "crct10dif". If we use "crct10dif" to find a matched algorithm in crypto_alg_list, it's possible "crct10dif-generic" is selected, because the code calls strcmp to decide if two string are exact match, but doesn't check if two strings have the same length.

exact = !strcmp(q->cra_driver_name, name);

So ,if "crct10dif-generic" is in front of "crct10dif-pclmul" in crypto_alg_list, it will be picked as the matched algorithm, even if it has lower priority than "crct10dif-pclmul".

---
 crypto/api.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
crypto/api.c +0 -0
index b16ce16..5b3d45a 100644

crypto/api.c static struct crypto_alg *__crypto_alg_lookup(const char *name, u32 type, · line 83

Quoted 9 lines
crypto/api.c +2 -1
@@ -76,7 +76,8 @@ static struct crypto_alg *__crypto_alg_lookup(const char *name, u32 type,
 		    ((struct crypto_larval *)q)->mask != mask)
 			continue;
 
-		exact = !strcmp(q->cra_driver_name, name);
+		exact = (strlen(name) == strlen(q->cra_driver_name)) &&
+				!strcmp(q->cra_driver_name, name);
 		fuzzy = !strcmp(q->cra_name, name);
 		if (!exact && !(fuzzy && q->cra_priority > best))
 			continue;

This is bogus. Please describe how you reproduced the problem.

The priority matching should work.

Cheers,

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
#2 lore raw

Please ignore this patch, we have seen some issues in older verison of linux kernel. But it doesn't seem to be an issue in the latest kernel.

thanks

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Herbert Xu
Sent: Tuesday, March 21, 2017 8:01 PM
To: Ming Ma (mingma) <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/1] crypto: If two strings are exact match, they must have same length.

Quoted 22 lines · Ming Ma

When both "crct10dif-pclmul" algorithm and "crct10dif-generic"
algorithm exist in crypto_alg_list, "crct10dif-pclmul" should be
selected, since it has higher priority than "crct10dif-generic".
However, both algorithms have the same cra_name "crct10dif". If we use
"crct10dif" to find a matched algorithm in crypto_alg_list, it's
possible "crct10dif-generic" is selected, because the code calls
strcmp to decide if two string are exact match, but doesn't check if two strings have the same length.

exact = !strcmp(q->cra_driver_name, name);

So ,if "crct10dif-generic" is in front of "crct10dif-pclmul" in crypto_alg_list, it will be picked as the matched algorithm, even if it has lower priority than "crct10dif-pclmul".

---
 crypto/api.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

crypto/api.c static struct crypto_alg *__crypto_alg_lookup(const char *name, u32 type, · line 83

Quoted 9 lines
crypto/api.c +2 -1
@@ -76,7 +76,8 @@ static struct crypto_alg *__crypto_alg_lookup(const char *name, u32 type,
 		    ((struct crypto_larval *)q)->mask != mask)
 			continue;
 
-		exact = !strcmp(q->cra_driver_name, name);
+		exact = (strlen(name) == strlen(q->cra_driver_name)) &&
+				!strcmp(q->cra_driver_name, name);
 		fuzzy = !strcmp(q->cra_name, name);
 		if (!exact && !(fuzzy && q->cra_priority > best))
 			continue;

This is bogus. Please describe how you reproduced the problem.

The priority matching should work.

Cheers,
--
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt