linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH linux-next] crypto: api - Avoid NULL pointer dereference in crypto_larval_destroy()
@ 2022-08-16 11:37 cgel.zte
  2022-08-16 18:48 ` Eric Biggers
  0 siblings, 1 reply; 2+ messages in thread
From: cgel.zte @ 2022-08-16 11:37 UTC (permalink / raw)
  To: davem; +Cc: herbert, linux-crypto, ye xingchen, Zeal Robot

From: ye xingchen <ye.xingchen@zte.com.cn>

When we have no primary larval or when it's a software node, we may end up
 in the situation when larval is a NULL pointer. There is no point to look
for secondary larval in such case. Add a necessary check to a condition.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: ye xingchen <ye.xingchen@zte.com.cn>
---
 crypto/api.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/api.c b/crypto/api.c
index 69508ae9345e..f2399aac831d 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -96,7 +96,7 @@ static void crypto_larval_destroy(struct crypto_alg *alg)
 	struct crypto_larval *larval = (void *)alg;
 
 	BUG_ON(!crypto_is_larval(alg));
-	if (!IS_ERR_OR_NULL(larval->adult))
+	if (larval && !IS_ERR_OR_NULL(larval->adult))
 		crypto_mod_put(larval->adult);
 	kfree(larval);
 }
-- 
2.25.1

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

* Re: [PATCH linux-next] crypto: api - Avoid NULL pointer dereference in crypto_larval_destroy()
  2022-08-16 11:37 [PATCH linux-next] crypto: api - Avoid NULL pointer dereference in crypto_larval_destroy() cgel.zte
@ 2022-08-16 18:48 ` Eric Biggers
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Biggers @ 2022-08-16 18:48 UTC (permalink / raw)
  To: cgel.zte; +Cc: davem, herbert, linux-crypto, ye xingchen, Zeal Robot

On Tue, Aug 16, 2022 at 11:37:22AM +0000, cgel.zte@gmail.com wrote:
> From: ye xingchen <ye.xingchen@zte.com.cn>
> 
> When we have no primary larval or when it's a software node, we may end up
>  in the situation when larval is a NULL pointer. There is no point to look
> for secondary larval in such case. Add a necessary check to a condition.
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: ye xingchen <ye.xingchen@zte.com.cn>
> ---
>  crypto/api.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/crypto/api.c b/crypto/api.c
> index 69508ae9345e..f2399aac831d 100644
> --- a/crypto/api.c
> +++ b/crypto/api.c
> @@ -96,7 +96,7 @@ static void crypto_larval_destroy(struct crypto_alg *alg)
>  	struct crypto_larval *larval = (void *)alg;
>  
>  	BUG_ON(!crypto_is_larval(alg));
> -	if (!IS_ERR_OR_NULL(larval->adult))
> +	if (larval && !IS_ERR_OR_NULL(larval->adult))
>  		crypto_mod_put(larval->adult);
>  	kfree(larval);
>  }
> -- 

How does this new NULL check do anything when the pointer is unconditionally
dereferenced in the previous line?

- Eric

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

end of thread, other threads:[~2022-08-16 18:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-16 11:37 [PATCH linux-next] crypto: api - Avoid NULL pointer dereference in crypto_larval_destroy() cgel.zte
2022-08-16 18:48 ` Eric Biggers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).