Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1685994

Re: [PATCH] slub: make sure struct kmem_cache_node is initialized before publication

From Andrew Morton <akpm@linux-foundation.org>
Newsgroups linux.kernel
Subject Re: [PATCH] slub: make sure struct kmem_cache_node is initialized before publication
Date 2017-07-12 21:30 +0200
Message-ID <u2vuG-3Ri-11@gated-at.bofh.it> (permalink)
References <u0wXT-1kR-3@gated-at.bofh.it> <u0I2Z-DO-7@gated-at.bofh.it> <u0KHv-2xj-1@gated-at.bofh.it> <u1NDk-1kS-11@gated-at.bofh.it> <u2qEF-Q6-23@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wed, 12 Jul 2017 16:11:28 +0200 Alexander Potapenko <glider@google.com> wrote:

> >> At creation time the kmem_cache structure is private and no one can run a
> >> free operation.
> I've double-checked the code path and this turned out to be a false
> positive caused by KMSAN not instrumenting the contents of mm/slub.c
> (i.e. the initialization of the spinlock remained unnoticed).
> Christoph is indeed right that kmem_cache_structure is private, so a
> race is not possible here.
> I am sorry for the false alarm.
> >> > Inviting a use-after-free?  I guess not, as there should be no way
> >> > to look up these items at this stage.
> >>
> >> Right.
> >
> > Still.   It looks bad, and other sites do these things in the other order.
> If the maintainers agree the initialization order needs to be fixed,
> we'll need to remove the (irrelevant) KMSAN report from the patch
> description.

Yup.  I did this:

From: Alexander Potapenko <glider@google.com>
Subject: slub: tidy up initialization ordering

- free_kmem_cache_nodes() frees the cache node before nulling out a
  reference to it

- init_kmem_cache_nodes() publishes the cache node before initializing it

Neither of these matter at runtime because the cache nodes cannot be
looked up by any other thread.  But it's neater and more consistent to
reorder these.

Link: http://lkml.kernel.org/r/20170707083408.40410-1-glider@google.com
Signed-off-by: Alexander Potapenko <glider@google.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>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/slub.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff -puN mm/slub.c~slub-make-sure-struct-kmem_cache_node-is-initialized-before-publication mm/slub.c
--- a/mm/slub.c~slub-make-sure-struct-kmem_cache_node-is-initialized-before-publication
+++ a/mm/slub.c
@@ -3358,8 +3358,8 @@ static void free_kmem_cache_nodes(struct
 	struct kmem_cache_node *n;
 
 	for_each_kmem_cache_node(s, node, n) {
-		kmem_cache_free(kmem_cache_node, n);
 		s->node[node] = NULL;
+		kmem_cache_free(kmem_cache_node, n);
 	}
 }
 
@@ -3389,8 +3389,8 @@ static int init_kmem_cache_nodes(struct
 			return 0;
 		}
 
-		s->node[node] = n;
 		init_kmem_cache_node(n);
+		s->node[node] = n;
 	}
 	return 1;
 }
_

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] slub: make sure struct kmem_cache_node is initialized before publication Alexander Potapenko <glider@google.com> - 2017-07-07 10:40 +0200
  Re: [PATCH] slub: make sure struct kmem_cache_node is initialized  before publication Alexander Potapenko <glider@google.com> - 2017-07-07 10:50 +0200
  Re: [PATCH] slub: make sure struct kmem_cache_node is initialized  before publication Andrew Morton <akpm@linux-foundation.org> - 2017-07-07 22:30 +0200
    Re: [PATCH] slub: make sure struct kmem_cache_node is initialized  before publication Christoph Lameter <cl@linux.com> - 2017-07-08 01:20 +0200
      Re: [PATCH] slub: make sure struct kmem_cache_node is initialized  before publication Alexander Potapenko <glider@google.com> - 2017-07-10 11:30 +0200
        Re: [PATCH] slub: make sure struct kmem_cache_node is initialized  before publication Christoph Lameter <cl@linux.com> - 2017-07-10 17:40 +0200
      Re: [PATCH] slub: make sure struct kmem_cache_node is initialized  before publication Andrew Morton <akpm@linux-foundation.org> - 2017-07-10 22:40 +0200
        Re: [PATCH] slub: make sure struct kmem_cache_node is initialized  before publication Alexander Potapenko <glider@google.com> - 2017-07-12 16:20 +0200
          Re: [PATCH] slub: make sure struct kmem_cache_node is initialized  before publication Andrew Morton <akpm@linux-foundation.org> - 2017-07-12 21:30 +0200
            Re: [PATCH] slub: make sure struct kmem_cache_node is initialized  before publication Christopher Lameter <cl@linux.com> - 2017-07-12 22:00 +0200

csiph-web