mm: slub: fix conversion of freelist_corrupted()
Subsystems (3)
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]/
--- mm/slub.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
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 ; + } do { prior = page->freelist;
Signature · 1 line
2.28.0
Andrew Morton
maintainerQuoted 23 lines · On Tue, 11 Aug 2020 14:46:56 +0200 Eugeniu Rosca <[email protected]> wrote:
Commit
52f23478081ae0("mm/slub.c: fix corrupted freechain indeactivate_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?
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 indeactivate_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
-0do { 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
Quoted 31 lines · Eugeniu Rosca
Commit
52f23478081ae0("mm/slub.c: fix corrupted freechain indeactivate_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]>Cc <[email protected]>Signed-off-by Eugeniu Rosca <[email protected]>--- mm/slub.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)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; }
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
Hello Dongli,
Quoted 41 lines · Dongli Zhang
Quoted 31 lines · Eugeniu Rosca
Commit
52f23478081ae0("mm/slub.c: fix corrupted freechain indeactivate_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]>Cc <[email protected]>Signed-off-by Eugeniu Rosca <[email protected]>--- mm/slub.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)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; }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_DEBUGis not defined.While reading the source code, people may be curious why to reset freelist when
CONFIG_SLUB_DEBUGis 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
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 indeactivate_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.Fixes 52f23478081ae0 ("mm/slub.c: fix corrupted freechain in deactivate_slab()")Cc Andrew Morton <[email protected]>Cc Dongli Zhang <[email protected]>Cc <[email protected]>Signed-off-by Eugeniu Rosca <[email protected]>--- mm/slub.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)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; }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_DEBUGis not defined.While reading the source code, people may be curious why to reset freelist when
CONFIG_SLUB_DEBUGis even not defined.This is a fair point. To address it, the
freelist = NULLassignment should be then moved into the body offreelist_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