Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1606014 > unrolled thread

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

Started byMing Ma <mingma@micron.com>
First post2017-03-21 22:50 +0100
Last post2017-03-22 04:10 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/1] crypto: If two strings are exact match, they must have same length. Ming Ma <mingma@micron.com> - 2017-03-21 22:50 +0100
    Re: [PATCH 1/1] crypto: If two strings are exact match, they must  have same length. Herbert Xu <herbert@gondor.apana.org.au> - 2017-03-22 04:10 +0100

#1606014 — [PATCH 1/1] crypto: If two strings are exact match, they must have same length.

FromMing Ma <mingma@micron.com>
Date2017-03-21 22:50 +0100
Subject[PATCH 1/1] crypto: If two strings are exact match, they must have same length.
Message-ID<tnzPc-Jo-17@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1606176 — Re: [PATCH 1/1] crypto: If two strings are exact match, they must have same length.

FromHerbert Xu <herbert@gondor.apana.org.au>
Date2017-03-22 04:10 +0100
SubjectRe: [PATCH 1/1] crypto: If two strings are exact match, they must have same length.
Message-ID<tnEOR-4iL-5@gated-at.bofh.it>
In reply to#1606014
On Tue, Mar 21, 2017 at 04:40:40PM -0500, Ming Ma wrote:
> 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;

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

The priority matching should work.

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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web