From: Jianqun Xu <jay.xu@xxxxxxxxxxxxxx> Subject: mm/cma.c: fix NULL pointer dereference when cma could not be activated 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. Link: http://lkml.kernel.org/r/20200615010123.15596-1-jay.xu@xxxxxxxxxxxxxx Signed-off-by: Jianqun Xu <jay.xu@xxxxxxxxxxxxxx> Reviewed-by: David Hildenbrand <david@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/cma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/mm/cma.c~mm-cma-fix-null-pointer-dereference-when-cma-could-not-be-activated +++ a/mm/cma.c @@ -425,7 +425,7 @@ struct page *cma_alloc(struct cma *cma, 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, _