linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Jianqun Xu <jay.xu@rock-chips.com>, akpm@linux-foundation.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/cma: fix NULL pointer dereference when cma could not be activated
Date: Mon, 15 Jun 2020 10:34:57 +0200	[thread overview]
Message-ID: <c30740af-d0fd-cac7-6304-d7f5ce25a9e6@redhat.com> (raw)
In-Reply-To: <20200615010123.15596-1-jay.xu@rock-chips.com>

On 15.06.20 03:01, Jianqun Xu wrote:
> In some case the cma area could not be activated, but the cma_alloc be
> used under this case, then the kernel will crash caused by NULL pointer
> dereference.
> 
> Add bitmap valid check in cma_alloc to avoid this issue.
> 
> Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
> ---
>  mm/cma.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/cma.c b/mm/cma.c
> index 0463ad2ce06b..488496fa2972 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -425,7 +425,7 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align,
>  	struct page *page = NULL;
>  	int ret = -ENOMEM;
>  
> -	if (!cma || !cma->count)
> +	if (!cma || !cma->count || !cma->bitmap)
>  		return NULL;
>  
>  	pr_debug("%s(cma %p, count %zu, align %d)\n", __func__, (void *)cma,
> 

If cma_activate_area() fails, cma_init_reserved_areas() fails. AFAIKS,
init/main.c will ignore any errors via do_one_initcall(). So this seems
to be possible.

Reviewed-by: David Hildenbrand <david@redhat.com>


-- 
Thanks,

David / dhildenb



      reply	other threads:[~2020-06-15  8:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-15  1:01 Jianqun Xu
2020-06-15  8:34 ` David Hildenbrand [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=c30740af-d0fd-cac7-6304-d7f5ce25a9e6@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=jay.xu@rock-chips.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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