From: Pekka Enberg Date: Sun, 6 May 2007 21:49:03 +0000 (-0700) Subject: slab: ensure cache_alloc_refill terminates X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=714b8171af9c930a59a0da8f6fe50518e70ab035;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git slab: ensure cache_alloc_refill terminates If slab->inuse is corrupted, cache_alloc_refill can enter an infinite loop as detailed by Michael Richardson in the following post: . This adds a BUG_ON to catch those cases. Cc: Michael Richardson Acked-by: Christoph Lameter Signed-off-by: Pekka Enberg Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/mm/slab.c b/mm/slab.c index 8b71a9c3daa4..21b2aef25254 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -2990,6 +2990,14 @@ retry: slabp = list_entry(entry, struct slab, list); check_slabp(cachep, slabp); check_spinlock_acquired(cachep); + + /* + * The slab was either on partial or free list so + * there must be at least one object available for + * allocation. + */ + BUG_ON(slabp->inuse < 0 || slabp->inuse >= cachep->num); + while (slabp->inuse < cachep->num && batchcount--) { STATS_INC_ALLOCED(cachep); STATS_INC_ACTIVE(cachep);