Skip to content

Commit

Permalink
mm/cma.c: fix NULL pointer dereference when cma could not be activated
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Reviewed-by: David Hildenbrand <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
jayxurockchip authored and torvalds committed Aug 12, 2020
1 parent 1a5bae2 commit 835832b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mm/cma.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 835832b

Please sign in to comment.