mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/1] crypto: If two strings are exact match, they must have same length.
@ 2017-03-21 21:40 Ming Ma
  2017-03-22  3:00 ` Herbert Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Ming Ma @ 2017-03-21 21:40 UTC (permalink / raw)
  To: herbert, davem; +Cc: linux-crypto, linux-kernel, 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".
Signed-off-by: Ming Ma <mingma@micron.com>
---
 crypto/api.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/crypto/api.c b/crypto/api.c
index b16ce16..5b3d45a 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -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;
-- 
2.4.11

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-03-27 23:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-21 21:40 [PATCH 1/1] crypto: If two strings are exact match, they must have same length Ming Ma
2017-03-22  3:00 ` Herbert Xu
2017-03-27 23:04   ` Ming Ma (mingma)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®