Message ID | 20220816113722.82894-1-ye.xingchen@zte.com.cn |
---|---|
State | New |
Headers | show |
Series | [linux-next] crypto: api - Avoid NULL pointer dereference in crypto_larval_destroy() | expand |
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
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); }