
From: Jianqun Xu <jay.xu@rock-chips.com> mainline inclusion from mainline-v5.9-rc1 commit 835832ba01bb444c7e45139e4b807527c119dafc category: bugfix bugzilla: 41397 CVE: NA ------------------------------------------------- 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> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: David Hildenbrand <david@redhat.com> Link: http://lkml.kernel.org/r/20200615010123.15596-1-jay.xu@rock-chips.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Liu Shixin <liushixin2@huawei.com> Reviewed-by: Chen Wandun <chenwandun@huawei.com> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> --- mm/cma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/cma.c b/mm/cma.c index 4c2864270a39b..f4df1bcbaf3ba 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -430,7 +430,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.25.1