Skip to contentSkip to conversation

mm: slub: fix conversion of freelist_corrupted()

PATCH Superseded Eugeniu Rosca 3 participants 6 messages Aug 11, 2020 – Aug 14, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: slub: fix conversion of freelist_corrupted()

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]. Prefer the lowest-line-count solution.

[1] https://lore.kernel.org/linux-mm/[email protected]/

Fixes 52f23478081ae0 ("mm/slub.c: fix corrupted freechain in deactivate_slab()")
Cc Andrew Morton <[email protected]>
Cc Dongli Zhang <[email protected]>
---
 mm/slub.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/slub.c +3 -2
index 68c02b2eecd9..9a3e963b02a3 100644
@@ -677,7 +677,6 @@ static bool freelist_corrupted(struct kmem_cache *s, struct page *page,
 	if ((s->flags & SLAB_CONSISTENCY_CHECKS) &&
 	    !check_valid_pointer(s, page, nextfree)) {
 		object_err(s, page, freelist, "Freechain corrupt");
-		freelist = NULL;
 		slab_fix(s, "Isolate corrupted freechain");
 		return true;
 	}
@@ -2184,8 +2183,10 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
 		 * 'freelist' is already corrupted.  So isolate all objects
 		 * starting at 'freelist'.
 		 */
-		if (freelist_corrupted(s, page, freelist, nextfree))
+		if (freelist_corrupted(s, page, freelist, nextfree)) {
+			freelist = NULL;
 			break;
+		}
 
 		do {
 			prior = page->freelist;
Signature · 1 line
2.28.0
maintainer
#1 lore raw
Quoted 23 lines · On Tue, 11 Aug 2020 14:46:56 +0200 Eugeniu Rosca <[email protected]> wrote:

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]. Prefer the lowest-line-count solution.

[1] https://lore.kernel.org/linux-mm/[email protected]/

...

mm/slub.c +0 -1
@@ -677,7 +677,6 @@ static bool freelist_corrupted(struct kmem_cache *s, struct page *page,
 	if ((s->flags & SLAB_CONSISTENCY_CHECKS) &&
 	    !check_valid_pointer(s, page, nextfree)) {
 		object_err(s, page, freelist, "Freechain corrupt");
-		freelist = NULL;
 		slab_fix(s, "Isolate corrupted freechain");
 		return true;
 	}
@@ -2184,8 +2183,10 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
 		 * 'freelist' is already corrupted.  So isolate all objects

mm/slub.c static void deactivate_slab(struct kmem_cache *s, struct page *page, · line 2192

Quoted 10 lines
mm/slub.c +3 -1
 		 * starting at 'freelist'.
 		 */
-		if (freelist_corrupted(s, page, freelist, nextfree))
+		if (freelist_corrupted(s, page, freelist, nextfree)) {
+			freelist = NULL;
 			break;
+		}
 
 		do {
 			prior = page->freelist;

Looks right.

What are the runtime effects of this change? In other words, what are the end user visible effects of the present defect?

#2 lore raw

Dear Andrew,

Quoted 33 lines · Andrew Morton
Quoted 31 lines · On Tue, 11 Aug 2020 14:46:56 +0200 Eugeniu Rosca <[email protected]> wrote:

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]. Prefer the lowest-line-count solution.

[1] https://lore.kernel.org/linux-mm/[email protected]/

...

mm/slub.c +3 -2
@@ -677,7 +677,6 @@ static bool freelist_corrupted(struct kmem_cache *s, struct page *page,
 	if ((s->flags & SLAB_CONSISTENCY_CHECKS) &&
 	    !check_valid_pointer(s, page, nextfree)) {
 		object_err(s, page, freelist, "Freechain corrupt");
-		freelist = NULL;
 		slab_fix(s, "Isolate corrupted freechain");
 		return true;
 	}
@@ -2184,8 +2183,10 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
 		 * 'freelist' is already corrupted.  So isolate all objects
 		 * starting at 'freelist'.
 		 */
-		if (freelist_corrupted(s, page, freelist, nextfree))
+		if (freelist_corrupted(s, page, freelist, nextfree)) {
+			freelist = NULL;
 			break;
+		}
 
Quoted 7 lines

mm/slub.c static void deactivate_slab(struct kmem_cache *s, struct page *page, · line 2192

Quoted 2 lines
mm/slub.c +0 -0
 		do {
 			prior = page->freelist;

Looks right.

What are the runtime effects of this change? In other words, what are the end user visible effects of the present defect?

Thank you for the prompt feedback.

The issue popped up as a result of static analysis and code review. Therefore, I lack any specific runtime behavior example being fixed. Nevertheless, I think this does not diminish the concern expressed in the description of the patch.

Signature · 2 lines
Best regards,
Eugeniu Rosca
#3 lore raw
In reply to Eugeniu Rosca
Quoted 31 lines · Eugeniu Rosca

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]. Prefer the lowest-line-count solution.

[1] https://lore.kernel.org/linux-mm/[email protected]/

Fixes 52f23478081ae0 ("mm/slub.c: fix corrupted freechain in deactivate_slab()")
Cc Andrew Morton <[email protected]>
Cc Dongli Zhang <[email protected]>
---
 mm/slub.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/slub.c +0 -1
index 68c02b2eecd9..9a3e963b02a3 100644
@@ -677,7 +677,6 @@ static bool freelist_corrupted(struct kmem_cache *s, struct page *page,
 	if ((s->flags & SLAB_CONSISTENCY_CHECKS) &&
 	    !check_valid_pointer(s, page, nextfree)) {
 		object_err(s, page, freelist, "Freechain corrupt");
-		freelist = NULL;
 		slab_fix(s, "Isolate corrupted freechain");
 		return true;
 	}

mm/slub.c static void deactivate_slab(struct kmem_cache *s, struct page *page, · line 2187

Quoted 6 lines
mm/slub.c +2 -1
@@ -2184,8 +2183,10 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
 		 * 'freelist' is already corrupted.  So isolate all objects
 		 * starting at 'freelist'.
 		 */
-		if (freelist_corrupted(s, page, freelist, nextfree))
+		if (freelist_corrupted(s, page, freelist, nextfree)) {
+			freelist = NULL;

This is good to me.

However, this would confuse people when CONFIG_SLUB_DEBUG is not defined.

While reading the source code, people may be curious why to reset freelist when CONFIG_SLUB_DEBUG is even not defined.

Dongli Zhang

#4 lore raw

Hello Dongli,

Quoted 41 lines · Dongli Zhang
Quoted 31 lines · Eugeniu Rosca

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]. Prefer the lowest-line-count solution.

[1] https://lore.kernel.org/linux-mm/[email protected]/

Fixes 52f23478081ae0 ("mm/slub.c: fix corrupted freechain in deactivate_slab()")
Cc Andrew Morton <[email protected]>
Cc Dongli Zhang <[email protected]>
---
 mm/slub.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/slub.c +0 -1
index 68c02b2eecd9..9a3e963b02a3 100644
@@ -677,7 +677,6 @@ static bool freelist_corrupted(struct kmem_cache *s, struct page *page,
 	if ((s->flags & SLAB_CONSISTENCY_CHECKS) &&
 	    !check_valid_pointer(s, page, nextfree)) {
 		object_err(s, page, freelist, "Freechain corrupt");
-		freelist = NULL;
 		slab_fix(s, "Isolate corrupted freechain");
 		return true;
 	}

mm/slub.c static void deactivate_slab(struct kmem_cache *s, struct page *page, · line 2187

Quoted 6 lines
mm/slub.c +2 -1
@@ -2184,8 +2183,10 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
 		 * 'freelist' is already corrupted.  So isolate all objects
 		 * starting at 'freelist'.
 		 */
-		if (freelist_corrupted(s, page, freelist, nextfree))
+		if (freelist_corrupted(s, page, freelist, nextfree)) {
+			freelist = NULL;

This is good to me.

Quoted 4 lines

However, this would confuse people when CONFIG_SLUB_DEBUG is not defined.

While reading the source code, people may be curious why to reset freelist when CONFIG_SLUB_DEBUG is even not defined.

This is a fair point. To address it, the freelist = NULL assignment should be then moved into the body of freelist_corrupted(). If no concerns on that, I will soon push a v2 implementing this proposal.

Signature · 2 lines
Best regards,
Eugeniu Rosca
#5 lore raw
Quoted 44 lines · Eugeniu Rosca

Hello Dongli,

Quoted 41 lines · Dongli Zhang
Quoted 31 lines · Eugeniu Rosca

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]. Prefer the lowest-line-count solution.

[1] https://urldefense.com/v3/__https://lore.kernel.org/linux-mm/[email protected]/__;!!GqivPVa7Brio!LkxH4qJ3WzKnO_nmONLWV-HAougEaefnp8UnI6qC_8j0SS9_9fkO6bOe68flixlQzx8$

Fixes 52f23478081ae0 ("mm/slub.c: fix corrupted freechain in deactivate_slab()")
Cc Andrew Morton <[email protected]>
Cc Dongli Zhang <[email protected]>
---
 mm/slub.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/slub.c +0 -1
index 68c02b2eecd9..9a3e963b02a3 100644
@@ -677,7 +677,6 @@ static bool freelist_corrupted(struct kmem_cache *s, struct page *page,
 	if ((s->flags & SLAB_CONSISTENCY_CHECKS) &&
 	    !check_valid_pointer(s, page, nextfree)) {
 		object_err(s, page, freelist, "Freechain corrupt");
-		freelist = NULL;
 		slab_fix(s, "Isolate corrupted freechain");
 		return true;
 	}

mm/slub.c static void deactivate_slab(struct kmem_cache *s, struct page *page, · line 2187

Quoted 6 lines
mm/slub.c +2 -1
@@ -2184,8 +2183,10 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
 		 * 'freelist' is already corrupted.  So isolate all objects
 		 * starting at 'freelist'.
 		 */
-		if (freelist_corrupted(s, page, freelist, nextfree))
+		if (freelist_corrupted(s, page, freelist, nextfree)) {
+			freelist = NULL;

This is good to me.

Quoted 9 lines
Quoted 4 lines

However, this would confuse people when CONFIG_SLUB_DEBUG is not defined.

While reading the source code, people may be curious why to reset freelist when CONFIG_SLUB_DEBUG is even not defined.

This is a fair point. To address it, the freelist = NULL assignment should be then moved into the body of freelist_corrupted(). If no concerns on that, I will soon push a v2 implementing this proposal.

I do have have concern with that if that can make both of static analysis tool and the people reading code happy :)

Thank you very much!

Dongli Zhang