Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit af2cf2c5 authored by Eugeniu Rosca's avatar Eugeniu Rosca Committed by Greg Kroah-Hartman
Browse files

mm: slub: fix conversion of freelist_corrupted()

commit dc07a728d49cf025f5da2c31add438d839d076c0 upstream.

Commit 52f23478081ae0 ("mm/slub.c: fix corrupted freechain in
deactivate_slab()") suffered an update when picked up from LKML [1].

Specifically, relocating 'freelist = NULL' into 'freelist_corrupted()'
created a no-op statement.  Fix it by sticking to the behavior intended
in the original patch [1].  In addition, make freelist_corrupted()
immune to passing NULL instead of &freelist.

The issue has been spotted via static analysis and code review.

[1] https://lore.kernel.org/linux-mm/20200331031450.12182-1-dongli.zhang@oracle.com/



Fixes: 52f23478081ae0 ("mm/slub.c: fix corrupted freechain in deactivate_slab()")
Signed-off-by: default avatarEugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Cc: Dongli Zhang <dongli.zhang@oracle.com>
Cc: Joe Jin <joe.jin@oracle.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: <stable@vger.kernel.org>
Link: https://lkml.kernel.org/r/20200824130643.10291-1-erosca@de.adit-jv.com


Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2c00ee62
Loading
Loading
Loading
Loading
+6 −6
Original line number Original line Diff line number Diff line
@@ -646,12 +646,12 @@ static void slab_fix(struct kmem_cache *s, char *fmt, ...)
}
}


static bool freelist_corrupted(struct kmem_cache *s, struct page *page,
static bool freelist_corrupted(struct kmem_cache *s, struct page *page,
			       void *freelist, void *nextfree)
			       void **freelist, void *nextfree)
{
{
	if ((s->flags & SLAB_CONSISTENCY_CHECKS) &&
	if ((s->flags & SLAB_CONSISTENCY_CHECKS) &&
	    !check_valid_pointer(s, page, nextfree)) {
	    !check_valid_pointer(s, page, nextfree) && freelist) {
		object_err(s, page, freelist, "Freechain corrupt");
		object_err(s, page, *freelist, "Freechain corrupt");
		freelist = NULL;
		*freelist = NULL;
		slab_fix(s, "Isolate corrupted freechain");
		slab_fix(s, "Isolate corrupted freechain");
		return true;
		return true;
	}
	}
@@ -1343,7 +1343,7 @@ static inline void dec_slabs_node(struct kmem_cache *s, int node,
							int objects) {}
							int objects) {}


static bool freelist_corrupted(struct kmem_cache *s, struct page *page,
static bool freelist_corrupted(struct kmem_cache *s, struct page *page,
			       void *freelist, void *nextfree)
			       void **freelist, void *nextfree)
{
{
	return false;
	return false;
}
}
@@ -2037,7 +2037,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
		 * 'freelist' is already corrupted.  So isolate all objects
		 * 'freelist' is already corrupted.  So isolate all objects
		 * starting at 'freelist'.
		 * starting at 'freelist'.
		 */
		 */
		if (freelist_corrupted(s, page, freelist, nextfree))
		if (freelist_corrupted(s, page, &freelist, nextfree))
			break;
			break;


		do {
		do {