Skip to content

Commit

Permalink
mm/z3fold: fix possible null pointer dereferencing
Browse files Browse the repository at this point in the history
alloc_slots could fail to allocate memory under heavy memory pressure.  So
we should check zhdr->slots against NULL to avoid future null pointer
dereferencing.

Link: https://lkml.kernel.org/r/[email protected]
Fixes: fc54886 ("z3fold: simplify freeing slots")
Signed-off-by: Miaohe Lin <[email protected]>
Reviewed-by: Vitaly Wool <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
MiaoheLin authored and akpm00 committed May 27, 2022
1 parent 4c6bdb3 commit 7c61c35
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion mm/z3fold.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,9 +940,19 @@ static inline struct z3fold_header *__z3fold_alloc(struct z3fold_pool *pool,
}
}

if (zhdr && !zhdr->slots)
if (zhdr && !zhdr->slots) {
zhdr->slots = alloc_slots(pool, GFP_ATOMIC);
if (!zhdr->slots)
goto out_fail;
}
return zhdr;

out_fail:
if (!kref_put(&zhdr->refcount, release_z3fold_page_locked)) {
add_to_unbuddied(pool, zhdr);
z3fold_page_unlock(zhdr);
}
return NULL;
}

/*
Expand Down

0 comments on commit 7c61c35

Please sign in to comment.