diff options
author | Miaohe Lin <linmiaohe@huawei.com> | 2022-04-29 08:40:43 +0200 |
---|---|---|
committer | akpm <akpm@linux-foundation.org> | 2022-05-27 18:33:43 +0200 |
commit | 7c61c35bbd6a888416e5a6de8ff8782a70d013d4 (patch) | |
tree | d062095fadf78cede1c32b05ceb42f05ad98d234 /mm | |
parent | mm/z3fold: fix sheduling while atomic (diff) | |
download | linux-7c61c35bbd6a888416e5a6de8ff8782a70d013d4.tar.xz linux-7c61c35bbd6a888416e5a6de8ff8782a70d013d4.zip |
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: fc5488651c7d ("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>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/z3fold.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/mm/z3fold.c b/mm/z3fold.c index c2260f5a5885..5d8c21f2bc59 100644 --- a/mm/z3fold.c +++ b/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; } /* |