linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Cc: herbert@gondor.apana.org.au, davem@davemloft.net,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] crypto: af_alg - check possible NULL pointer
Date: Thu, 30 Dec 2021 16:57:40 -0600	[thread overview]
Message-ID: <Yc45ZPItDFcDaCNv@quark> (raw)
In-Reply-To: <20211229093216.1753083-1-jiasheng@iscas.ac.cn>

On Wed, Dec 29, 2021 at 05:32:16PM +0800, Jiasheng Jiang wrote:
> And then it will cause the BUG_ON() in sg_assign_page().

That's not true.  The two BUG_ON()'s in sg_assign_page() are:

        BUG_ON((unsigned long) page & (SG_CHAIN | SG_END));
#ifdef CONFIG_DEBUG_SG
        BUG_ON(sg_is_chain(sg));
#endif

Neither will trigger due to page == NULL.

>  		do {
> +			struct page *pg;
>  			unsigned int i = sgl->cur;
>  
>  			plen = min_t(size_t, len, PAGE_SIZE);
>  
> -			sg_assign_page(sg + i, alloc_page(GFP_KERNEL));
> +			pg = alloc_page(GFP_KERNEL);
> +			if (!pg) {
> +				err = -ENOMEM;
> +				goto unlock;
> +			}
> +
> +			sg_assign_page(sg + i, pg);
>  			if (!sg_page(sg + i)) {
>  				err = -ENOMEM;
>  				goto unlock;

The NULL check is already done, just below the redundant one you're adding.

I do think it would be more logical to do the NULL check before
sg_assign_page().  So you could send a patch that moves it there.  But it would
be a cleanup, not a fix.

- Eric

      reply	other threads:[~2021-12-30 22:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-29  9:32 [PATCH] crypto: af_alg - check possible NULL pointer Jiasheng Jiang
2021-12-30 22:57 ` Eric Biggers [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yc45ZPItDFcDaCNv@quark \
    --to=ebiggers@kernel.org \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=jiasheng@iscas.ac.cn \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).