crypto: lrw - Fixes for the 'create()' function
Subsystems (2)
cover crypto: lrw - Fixes for the 'create()' function
The first patch is the same as the one committed for crypto/xts.c applied a few days ago.
(commit 5125e4e867ab ("crypto: xts - Fix an error handling path in 'create()'") in /git/herbert/crypto-2.6.git)
The 2nd one is a pure speculation from me.
The create function in 'crypto/xts.c' and 'crypto/lrw.c' look very similar.
However, there is one more sanity check in xts. This patch proposes to add the same test in lrw. Not sure at all if correct!
I just send it for consistency.
Christophe JAILLET (2):
crypto: lrw - Fix an error handling path in 'create()'
crypto: lrw - Check for incorrect cipher name
crypto/lrw.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/2 crypto: lrw - Fix an error handling path in 'create()'
All error handling paths 'goto err_drop_spawn' except this one. In order to avoid some resources leak, we should do it as well here.
--- crypto/lrw.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
crypto/lrw.c +4 -2
@@ -610,8 +610,10 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb) ecb_name[len -1 ] =0 ;if (snprintf (inst->alg.base.cra_name,CRYPTO_MAX_ALG_NAME , -"lrw(%s)" , ecb_name) >=CRYPTO_MAX_ALG_NAME ) -return -ENAMETOOLONG ; +"lrw(%s)" , ecb_name) >=CRYPTO_MAX_ALG_NAME ) { + err = -ENAMETOOLONG ; + goto err_drop_spawn; + } } inst->alg.base.cra_flags = alg->base.cra_flags &CRYPTO_ALG_ASYNC ;
Signature · 1 line
2.11.0
PATCH 2/2 crypto: lrw - Check for incorrect cipher name
In reply to Christophe JAILLETIf the cipher name does not start with 'ecb(' we should bail out, as done in the 'create()' function in 'crypto/xts.c'.
---
This patch is 100% speculative.
It is based on comparison with the 'create()' function from 'crypto/xts.c' Code looks the same, but this aditionnal test is in xts.c and not in lrw.c.
The 2 should maybe be consistent?
--- crypto/lrw.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
crypto/lrw.c +2 -1
@@ -614,7 +614,8 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb) err = -ENAMETOOLONG ; goto err_drop_spawn; } - } + }else + goto err_drop_spawn; inst->alg.base.cra_flags = alg->base.cra_flags &CRYPTO_ALG_ASYNC ; inst->alg.base.cra_priority = alg->base.cra_priority;
Signature · 1 line
2.11.0
Re: [PATCH 1/2] crypto: lrw - Fix an error handling path in 'create()'
In reply to Christophe JAILLETAm 08.10.2017 11:39, schrieb Christophe JAILLET:
Quoted 14 lines
All error handling paths 'goto
err_drop_spawn' except this one. In order to avoid some resources leak, we should do it as well here.Fixes 700cb3f5fe75 ("crypto: lrw - Convert to skcipher")Signed-off-by Christophe JAILLET <[email protected]>--- crypto/lrw.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)crypto/lrw.c +0
-0
crypto/lrw.c static int create(struct crypto_template *tmpl, struct rtattr **tb) · line 613
Quoted 4 lines
crypto/lrw.c +0
-1@@ -610,8 +610,10 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb) ecb_name[len -1 ] =0 ; if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, -"lrw(%s)" , ecb_name) >=CRYPTO_MAX_ALG_NAME )
this check can be done more easy,
the length of ecb_name is len
the length of inst->alg.base.cra_name is CRYPTO_MAX_ALG_NAME if CRYPTO_MAX_ALG_NAME-len < "lrw()" < 5
no need to involve snprintf()
just my 2 cents
re,
wh
Quoted 8 lines
crypto/lrw.c +4
-1-return -ENAMETOOLONG ; + "lrw(%s)", ecb_name) >= CRYPTO_MAX_ALG_NAME) { + err = -ENAMETOOLONG ; + goto err_drop_spawn; + } } inst->alg.base.cra_flags = alg->base.cra_flags &CRYPTO_ALG_ASYNC ;
Re: [PATCH 1/2] crypto: lrw - Fix an error handling path in 'create()'
Le 09/10/2017 à 23:22, walter harms a écrit :
Quoted 25 lines
Am 08.10.2017 11:39, schrieb Christophe JAILLET:
Quoted 14 lines
All error handling paths 'goto
err_drop_spawn' except this one. In order to avoid some resources leak, we should do it as well here.Fixes 700cb3f5fe75 ("crypto: lrw - Convert to skcipher")Signed-off-by Christophe JAILLET <[email protected]>--- crypto/lrw.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)crypto/lrw.c +0
-0crypto/lrw.c static int create(struct crypto_template *tmpl, struct rtattr **tb) · line 613
Quoted 4 lines
crypto/lrw.c +0
-1@@ -610,8 +610,10 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb) ecb_name[len -1 ] =0 ; if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, -"lrw(%s)" , ecb_name) >=CRYPTO_MAX_ALG_NAME )this check can be done more easy,
the length ofecb_nameis len
the length ofinst->alg.base.cra_nameisCRYPTO_MAX_ALG_NAMEif CRYPTO_MAX_ALG_NAME-len < "lrw()" < 5
no need to involvesnprintf()
Quoted 3 lines
just my 2 cents
re,
wh
It does not only check for the length, it also copies some data. The test should be read: "If the copy succeeds (i.e if there is enough space for the copy to succeed)", and not "if the string is too long". IMHO, the snprintf is just fine here.
CJ
Quoted 8 lines
Quoted 8 lines
crypto/lrw.c +4
-1-return -ENAMETOOLONG ; + "lrw(%s)", ecb_name) >= CRYPTO_MAX_ALG_NAME) { + err = -ENAMETOOLONG ; + goto err_drop_spawn; + } } inst->alg.base.cra_flags = alg->base.cra_flags &CRYPTO_ALG_ASYNC ;
Re: [PATCH 1/2] crypto: lrw - Fix an error handling path in 'create()'
Am 10.10.2017 08:05, schrieb Christophe JAILLET:
Quoted 26 lines · walter harms
Quoted 25 lines
Am 08.10.2017 11:39, schrieb Christophe JAILLET:
Quoted 14 lines
All error handling paths 'goto
err_drop_spawn' except this one. In order to avoid some resources leak, we should do it as well here.Fixes 700cb3f5fe75 ("crypto: lrw - Convert to skcipher")Signed-off-by Christophe JAILLET <[email protected]>--- crypto/lrw.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)crypto/lrw.c +0
-0crypto/lrw.c static int create(struct crypto_template *tmpl, · line 613
Quoted 4 lines
crypto/lrw.c +0
-1@@ -610,8 +610,10 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb) ecb_name[len -1 ] =0 ; if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, -"lrw(%s)" , ecb_name) >=CRYPTO_MAX_ALG_NAME )this check can be done more easy,
the length ofecb_nameis len
the length ofinst->alg.base.cra_nameisCRYPTO_MAX_ALG_NAMEif CRYPTO_MAX_ALG_NAME-len < "lrw()" < 5
no need to involvesnprintf()
Quoted 7 lines
Quoted 3 lines
just my 2 cents
re,
whIt does not only check for the length, it also copies some data. The test should be read: "If the copy succeeds (i.e if there is enough space for the copy to succeed)", and not "if the string is too long". IMHO, the snprintf is just fine here.
under "normal" circumstance i would say "does not matter" when something ends up as crippled string but in case of crypto sameone (the maintainer) needs to be careful. I have no idea about the consequences, i can only point to strange looking things and say "be careful".
re,
wh
Quoted 18 lines
CJ
Quoted 8 lines
Quoted 8 lines
crypto/lrw.c +4
-1-return -ENAMETOOLONG ; + "lrw(%s)", ecb_name) >= CRYPTO_MAX_ALG_NAME) { + err = -ENAMETOOLONG ; + goto err_drop_spawn; + } } inst->alg.base.cra_flags = alg->base.cra_flags &CRYPTO_ALG_ASYNC ;Signature · 4 lines
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Herbert Xu
maintainerQuoted 12 lines · Christophe JAILLET
The first patch is the same as the one committed for
crypto/xts.capplied a few days ago.
(commit5125e4e867ab("crypto: xts - Fix an error handling path in 'create()'") in /git/herbert/crypto-2.6.git)The 2nd one is a pure speculation from me.
The create function in 'crypto/xts.c' and 'crypto/lrw.c' look very similar.
However, there is one more sanity check in xts. This patch proposes to add the same test in lrw. Not sure at all if correct!
I just send it for consistency.
Quoted 3 lines
Christophe JAILLET (2):
crypto: lrw - Fix an error handling path in 'create()'
crypto: lrw - Check for incorrect cipher name
All applied. 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