Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1622970 > unrolled thread
| Started by | Christophe JAILLET <christophe.jaillet@wanadoo.fr> |
|---|---|
| First post | 2017-04-13 14:20 +0200 |
| Last post | 2017-04-13 18:50 +0200 |
| Articles | 6 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 2/2] crypto: chcr - Fix error checking Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2017-04-13 14:20 +0200
Re: [PATCH 2/2] crypto: chcr - Fix error checking Dan Carpenter <dan.carpenter@oracle.com> - 2017-04-13 16:10 +0200
Re: [PATCH 2/2] crypto: chcr - Fix error checking Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2017-04-13 17:00 +0200
Re: [PATCH 2/2] crypto: chcr - Fix error checking Harsh Jain <harshjain.prof@gmail.com> - 2017-04-13 17:10 +0200
Re: [PATCH 2/2] crypto: chcr - Fix error checking Dan Carpenter <dan.carpenter@oracle.com> - 2017-04-13 18:20 +0200
Re: [PATCH 2/2] crypto: chcr - Fix error checking Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2017-04-13 18:50 +0200
| From | Christophe JAILLET <christophe.jaillet@wanadoo.fr> |
|---|---|
| Date | 2017-04-13 14:20 +0200 |
| Subject | [PATCH 2/2] crypto: chcr - Fix error checking |
| Message-ID | <tvLTc-2Sx-27@gated-at.bofh.it> |
If 'chcr_alloc_shash()' a few lines above fails, 'base_hash' can be an error pointer when we 'goto out'. So checking for NULL here is not enough because it is likely that 'chcr_free_shash' will crash if we pass an error pointer. Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> --- Another solution, amybe safer, would be to instrument 'chcr_free_shash' or 'crypto_free_shash' to accept an error pointer and return immediatelly in such a case. --- drivers/crypto/chelsio/chcr_algo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/crypto/chelsio/chcr_algo.c b/drivers/crypto/chelsio/chcr_algo.c index f19590ac8775..41750b97f43c 100644 --- a/drivers/crypto/chelsio/chcr_algo.c +++ b/drivers/crypto/chelsio/chcr_algo.c @@ -2351,7 +2351,7 @@ static int chcr_authenc_setkey(struct crypto_aead *authenc, const u8 *key, } out: aeadctx->enckey_len = 0; - if (base_hash) + if (!IS_ERR_OR_NULL(base_hash)) chcr_free_shash(base_hash); return -EINVAL; } -- 2.11.0
[toc] | [next] | [standalone]
| From | Dan Carpenter <dan.carpenter@oracle.com> |
|---|---|
| Date | 2017-04-13 16:10 +0200 |
| Message-ID | <tvNBE-43N-17@gated-at.bofh.it> |
| In reply to | #1622970 |
On Thu, Apr 13, 2017 at 02:14:30PM +0200, Christophe JAILLET wrote: > If 'chcr_alloc_shash()' a few lines above fails, 'base_hash' can be an > error pointer when we 'goto out'. > So checking for NULL here is not enough because it is likely that > 'chcr_free_shash' will crash if we pass an error pointer. > > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> > --- > Another solution, amybe safer, would be to instrument 'chcr_free_shash' or > 'crypto_free_shash' to accept an error pointer and return immediatelly in > such a case. > --- > drivers/crypto/chelsio/chcr_algo.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/crypto/chelsio/chcr_algo.c b/drivers/crypto/chelsio/chcr_algo.c > index f19590ac8775..41750b97f43c 100644 > --- a/drivers/crypto/chelsio/chcr_algo.c > +++ b/drivers/crypto/chelsio/chcr_algo.c > @@ -2351,7 +2351,7 @@ static int chcr_authenc_setkey(struct crypto_aead *authenc, const u8 *key, > } > out: > aeadctx->enckey_len = 0; > - if (base_hash) > + if (!IS_ERR_OR_NULL(base_hash)) > chcr_free_shash(base_hash); Ah... Ok. Fine, but redo the first patch anyway because it shouldn't ever be NULL. regards, dan carpenter
[toc] | [prev] | [next] | [standalone]
| From | Christophe JAILLET <christophe.jaillet@wanadoo.fr> |
|---|---|
| Date | 2017-04-13 17:00 +0200 |
| Message-ID | <tvOo3-4nr-35@gated-at.bofh.it> |
| In reply to | #1623061 |
Le 13/04/2017 à 16:04, Dan Carpenter a écrit :
> On Thu, Apr 13, 2017 at 02:14:30PM +0200, Christophe JAILLET wrote:
>> If 'chcr_alloc_shash()' a few lines above fails, 'base_hash' can be an
>> error pointer when we 'goto out'.
>> So checking for NULL here is not enough because it is likely that
>> 'chcr_free_shash' will crash if we pass an error pointer.
>>
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>> Another solution, amybe safer, would be to instrument 'chcr_free_shash' or
>> 'crypto_free_shash' to accept an error pointer and return immediatelly in
>> such a case.
>> ---
>> drivers/crypto/chelsio/chcr_algo.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/crypto/chelsio/chcr_algo.c b/drivers/crypto/chelsio/chcr_algo.c
>> index f19590ac8775..41750b97f43c 100644
>> --- a/drivers/crypto/chelsio/chcr_algo.c
>> +++ b/drivers/crypto/chelsio/chcr_algo.c
>> @@ -2351,7 +2351,7 @@ static int chcr_authenc_setkey(struct crypto_aead *authenc, const u8 *key,
>> }
>> out:
>> aeadctx->enckey_len = 0;
>> - if (base_hash)
>> + if (!IS_ERR_OR_NULL(base_hash))
>> chcr_free_shash(base_hash);
> Ah... Ok. Fine, but redo the first patch anyway because it shouldn't
> ever be NULL.
>
> regards,
> dan carpenter
Hi Dan,
I will update the first patch as you proposed in order to:
- teach 'chcr_alloc_shash' not to return NULL
- initialize 'base_hash' with ERR_PTR(-EINVAL)
- update the above test to !IS_ERR.
The 2 patches will be merged in only 1.
Thanks for your suggestions.
Best regards,
CJ
[toc] | [prev] | [next] | [standalone]
| From | Harsh Jain <harshjain.prof@gmail.com> |
|---|---|
| Date | 2017-04-13 17:10 +0200 |
| Message-ID | <tvOxH-4GB-1@gated-at.bofh.it> |
| In reply to | #1623107 |
On Thu, Apr 13, 2017 at 8:20 PM, Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
> Le 13/04/2017 à 16:04, Dan Carpenter a écrit :
>>
>> On Thu, Apr 13, 2017 at 02:14:30PM +0200, Christophe JAILLET wrote:
>>>
>>> If 'chcr_alloc_shash()' a few lines above fails, 'base_hash' can be an
>>> error pointer when we 'goto out'.
>>> So checking for NULL here is not enough because it is likely that
>>> 'chcr_free_shash' will crash if we pass an error pointer.
>>>
>>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>>> ---
>>> Another solution, amybe safer, would be to instrument 'chcr_free_shash'
>>> or
>>> 'crypto_free_shash' to accept an error pointer and return immediatelly in
>>> such a case.
>>> ---
>>> drivers/crypto/chelsio/chcr_algo.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/crypto/chelsio/chcr_algo.c
>>> b/drivers/crypto/chelsio/chcr_algo.c
>>> index f19590ac8775..41750b97f43c 100644
>>> --- a/drivers/crypto/chelsio/chcr_algo.c
>>> +++ b/drivers/crypto/chelsio/chcr_algo.c
>>> @@ -2351,7 +2351,7 @@ static int chcr_authenc_setkey(struct crypto_aead
>>> *authenc, const u8 *key,
>>> }
>>> out:
>>> aeadctx->enckey_len = 0;
>>> - if (base_hash)
>>> + if (!IS_ERR_OR_NULL(base_hash))
>>> chcr_free_shash(base_hash);
>>
>> Ah... Ok. Fine, but redo the first patch anyway because it shouldn't
>> ever be NULL.
>>
>> regards,
>> dan carpenter
>
> Hi Dan,
>
> I will update the first patch as you proposed in order to:
> - teach 'chcr_alloc_shash' not to return NULL
> - initialize 'base_hash' with ERR_PTR(-EINVAL)
> - update the above test to !IS_ERR.
> The 2 patches will be merged in only 1.
>
> Thanks for your suggestions.
Thanks for pointing the error. or You can simply return instead of
goto. Just like that.
1.3 @@ -2455,7 +2455,8 @@ static int chcr_authenc_setkey(struct cr
1.4 base_hash = chcr_alloc_shash(max_authsize);
1.5 if (IS_ERR(base_hash)) {
1.6 pr_err("chcr : Base driver cannot be loaded\n");
1.7 - goto out;
1.8 + aeadctx->enckey_len = 0;
1.9 + return -EINVAL;
1.10 }
1.11 {
1.12 SHASH_DESC_ON_STACK(shash, base_hash);
>
> Best regards,
> CJ
>
[toc] | [prev] | [next] | [standalone]
| From | Dan Carpenter <dan.carpenter@oracle.com> |
|---|---|
| Date | 2017-04-13 18:20 +0200 |
| Message-ID | <tvPDs-5oA-11@gated-at.bofh.it> |
| In reply to | #1623111 |
On Thu, Apr 13, 2017 at 08:37:50PM +0530, Harsh Jain wrote:
> On Thu, Apr 13, 2017 at 8:20 PM, Christophe JAILLET
> <christophe.jaillet@wanadoo.fr> wrote:
> > Le 13/04/2017 à 16:04, Dan Carpenter a écrit :
> >>
> >> On Thu, Apr 13, 2017 at 02:14:30PM +0200, Christophe JAILLET wrote:
> >>>
> >>> If 'chcr_alloc_shash()' a few lines above fails, 'base_hash' can be an
> >>> error pointer when we 'goto out'.
> >>> So checking for NULL here is not enough because it is likely that
> >>> 'chcr_free_shash' will crash if we pass an error pointer.
> >>>
> >>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> >>> ---
> >>> Another solution, amybe safer, would be to instrument 'chcr_free_shash'
> >>> or
> >>> 'crypto_free_shash' to accept an error pointer and return immediatelly in
> >>> such a case.
> >>> ---
> >>> drivers/crypto/chelsio/chcr_algo.c | 2 +-
> >>> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>>
> >>> diff --git a/drivers/crypto/chelsio/chcr_algo.c
> >>> b/drivers/crypto/chelsio/chcr_algo.c
> >>> index f19590ac8775..41750b97f43c 100644
> >>> --- a/drivers/crypto/chelsio/chcr_algo.c
> >>> +++ b/drivers/crypto/chelsio/chcr_algo.c
> >>> @@ -2351,7 +2351,7 @@ static int chcr_authenc_setkey(struct crypto_aead
> >>> *authenc, const u8 *key,
> >>> }
> >>> out:
> >>> aeadctx->enckey_len = 0;
> >>> - if (base_hash)
> >>> + if (!IS_ERR_OR_NULL(base_hash))
> >>> chcr_free_shash(base_hash);
> >>
> >> Ah... Ok. Fine, but redo the first patch anyway because it shouldn't
> >> ever be NULL.
> >>
> >> regards,
> >> dan carpenter
> >
> > Hi Dan,
> >
> > I will update the first patch as you proposed in order to:
> > - teach 'chcr_alloc_shash' not to return NULL
> > - initialize 'base_hash' with ERR_PTR(-EINVAL)
> > - update the above test to !IS_ERR.
> > The 2 patches will be merged in only 1.
> >
> > Thanks for your suggestions.
>
> Thanks for pointing the error. or You can simply return instead of
> goto. Just like that.
>
> 1.3 @@ -2455,7 +2455,8 @@ static int chcr_authenc_setkey(struct cr
> 1.4 base_hash = chcr_alloc_shash(max_authsize);
> 1.5 if (IS_ERR(base_hash)) {
> 1.6 pr_err("chcr : Base driver cannot be loaded\n");
> 1.7 - goto out;
> 1.8 + aeadctx->enckey_len = 0;
> 1.9 + return -EINVAL;
Don't do that. There should be a goto.
regards,
dan carpenter
[toc] | [prev] | [next] | [standalone]
| From | Christophe JAILLET <christophe.jaillet@wanadoo.fr> |
|---|---|
| Date | 2017-04-13 18:50 +0200 |
| Message-ID | <tvQ6u-5Bw-23@gated-at.bofh.it> |
| In reply to | #1623156 |
Le 13/04/2017 à 18:13, Dan Carpenter a écrit :
> On Thu, Apr 13, 2017 at 08:37:50PM +0530, Harsh Jain wrote:
>> On Thu, Apr 13, 2017 at 8:20 PM, Christophe JAILLET
>> <christophe.jaillet@wanadoo.fr> wrote:
>>> Le 13/04/2017 à 16:04, Dan Carpenter a écrit :
>>>> On Thu, Apr 13, 2017 at 02:14:30PM +0200, Christophe JAILLET wrote:
>>>>> If 'chcr_alloc_shash()' a few lines above fails, 'base_hash' can be an
>>>>> error pointer when we 'goto out'.
>>>>> So checking for NULL here is not enough because it is likely that
>>>>> 'chcr_free_shash' will crash if we pass an error pointer.
>>>>>
>>>>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>>>>> ---
>>>>> Another solution, amybe safer, would be to instrument 'chcr_free_shash'
>>>>> or
>>>>> 'crypto_free_shash' to accept an error pointer and return immediatelly in
>>>>> such a case.
>>>>> ---
>>>>> drivers/crypto/chelsio/chcr_algo.c | 2 +-
>>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/drivers/crypto/chelsio/chcr_algo.c
>>>>> b/drivers/crypto/chelsio/chcr_algo.c
>>>>> index f19590ac8775..41750b97f43c 100644
>>>>> --- a/drivers/crypto/chelsio/chcr_algo.c
>>>>> +++ b/drivers/crypto/chelsio/chcr_algo.c
>>>>> @@ -2351,7 +2351,7 @@ static int chcr_authenc_setkey(struct crypto_aead
>>>>> *authenc, const u8 *key,
>>>>> }
>>>>> out:
>>>>> aeadctx->enckey_len = 0;
>>>>> - if (base_hash)
>>>>> + if (!IS_ERR_OR_NULL(base_hash))
>>>>> chcr_free_shash(base_hash);
>>>> Ah... Ok. Fine, but redo the first patch anyway because it shouldn't
>>>> ever be NULL.
>>>>
>>>> regards,
>>>> dan carpenter
>>> Hi Dan,
>>>
>>> I will update the first patch as you proposed in order to:
>>> - teach 'chcr_alloc_shash' not to return NULL
>>> - initialize 'base_hash' with ERR_PTR(-EINVAL)
>>> - update the above test to !IS_ERR.
>>> The 2 patches will be merged in only 1.
>>>
>>> Thanks for your suggestions.
>> Thanks for pointing the error. or You can simply return instead of
>> goto. Just like that.
>>
>> 1.3 @@ -2455,7 +2455,8 @@ static int chcr_authenc_setkey(struct cr
>> 1.4 base_hash = chcr_alloc_shash(max_authsize);
>> 1.5 if (IS_ERR(base_hash)) {
>> 1.6 pr_err("chcr : Base driver cannot be loaded\n");
>> 1.7 - goto out;
>> 1.8 + aeadctx->enckey_len = 0;
>> 1.9 + return -EINVAL;
> Don't do that. There should be a goto.
>
> regards,
> dan carpenter
>
>
Agreed.
Having direct return after some other gotos statement puzzles my
coccinelle scripts and are spurious (at least IMHO).
best regards,
CJ
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web