mm/z3fold: fix possible null pointer dereferencing
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/20220429064051.61552-3-linmiaohe@huawei.com
Fixes: fc5488651c
("z3fold: simplify freeing slots")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Reviewed-by: Vitaly Wool <vitaly.wool@konsulko.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
4c6bdb3640
commit
7c61c35bbd
12
mm/z3fold.c
12
mm/z3fold.c
|
@ -940,9 +940,19 @@ lookup:
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue