* [PATCH] mm/cma: fix NULL pointer dereference when cma could not be activated
@ 2020-06-15 1:01 Jianqun Xu
2020-06-15 8:34 ` David Hildenbrand
0 siblings, 1 reply; 2+ messages in thread
From: Jianqun Xu @ 2020-06-15 1:01 UTC (permalink / raw)
To: akpm; +Cc: linux-mm, linux-kernel, Jianqun Xu
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,
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mm/cma: fix NULL pointer dereference when cma could not be activated
2020-06-15 1:01 [PATCH] mm/cma: fix NULL pointer dereference when cma could not be activated Jianqun Xu
@ 2020-06-15 8:34 ` David Hildenbrand
0 siblings, 0 replies; 2+ messages in thread
From: David Hildenbrand @ 2020-06-15 8:34 UTC (permalink / raw)
To: Jianqun Xu, akpm; +Cc: linux-mm, linux-kernel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-06-15 8:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-15 1:01 [PATCH] mm/cma: fix NULL pointer dereference when cma could not be activated Jianqun Xu
2020-06-15 8:34 ` David Hildenbrand
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).