Commit 7c61c35b authored by Miaohe Lin's avatar Miaohe Lin Committed by Andrew Morton
Browse files

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: fc548865 ("z3fold: simplify freeing slots")
Signed-off-by: default avatarMiaohe Lin <linmiaohe@huawei.com>
Reviewed-by: default avatarVitaly Wool <vitaly.wool@konsulko.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 4c6bdb36
Loading
Loading
Loading
Loading
+11 −1
Original line number Original line Diff line number Diff line
@@ -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);
		zhdr->slots = alloc_slots(pool, GFP_ATOMIC);
		if (!zhdr->slots)
			goto out_fail;
	}
	return zhdr;
	return zhdr;

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


/*
/*