From: Jianqun Xu Date: Wed, 12 Aug 2020 01:31:54 +0000 (-0700) Subject: mm/cma.c: fix NULL pointer dereference when cma could not be activated X-Git-Tag: v5.9-rc1~52^2~133 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=835832ba01bb444c7e45139e4b807527c119dafc;p=thirdparty%2Flinux.git 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. Signed-off-by: Jianqun Xu Signed-off-by: Andrew Morton Reviewed-by: David Hildenbrand Link: http://lkml.kernel.org/r/20200615010123.15596-1-jay.xu@rock-chips.com Signed-off-by: Linus Torvalds --- diff --git a/mm/cma.c b/mm/cma.c index 26ecff8188817..3a18f8d8ea5e9 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,