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/[email protected]
Fixes: fc5488651c ("z3fold: simplify freeing slots")
Signed-off-by: Miaohe Lin <[email protected]>
Reviewed-by: Vitaly Wool <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
This commit is contained in:
Miaohe Lin authored and akpm committed 2022-05-27 09:33:43 -07:00
1 parent 4c6bdb3640
commit 7c61c35bbd
1 file changed
+11 -1
+11 -1
View File
@@ -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;
}
/*