]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mm/z3fold: fix possible null pointer dereferencing
authorMiaohe Lin <linmiaohe@huawei.com>
Fri, 29 Apr 2022 06:40:43 +0000 (14:40 +0800)
committerakpm <akpm@linux-foundation.org>
Fri, 27 May 2022 16:33:43 +0000 (09:33 -0700)
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>
mm/z3fold.c

index c2260f5a5885709d2fba5ce2430cd1ba639af77f..5d8c21f2bc59266efb2aed612954d445fb6a8e81 100644 (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;
 }
 
 /*