diff options
| author | Thomas Gleixner <tglx@linutronix.de> | 2017-06-02 17:46:25 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-06-02 18:07:37 -0400 |
| commit | 478fe3037b2278d276d4cd9cd0ab06c4cb2e9b32 (patch) | |
| tree | b8fe57e18e2de964795b27e4b846fc4de7ace302 /mm | |
| parent | 57ddfdaa9a72fe726a44d26d99db31bc137dbeff (diff) | |
slub/memcg: cure the brainless abuse of sysfs attributes
memcg_propagate_slab_attrs() abuses the sysfs attribute file functions
to propagate settings from the root kmem_cache to a newly created
kmem_cache. It does that with:
attr->show(root, buf);
attr->store(new, buf, strlen(bug);
Aside of being a lazy and absurd hackery this is broken because it does
not check the return value of the show() function.
Some of the show() functions return 0 w/o touching the buffer. That
means in such a case the store function is called with the stale content
of the previous show(). That causes nonsense like invoking
kmem_cache_shrink() on a newly created kmem_cache. In the worst case it
would cause handing in an uninitialized buffer.
This should be rewritten proper by adding a propagate() callback to
those slub_attributes which must be propagated and avoid that insane
conversion to and from ASCII, but that's too large for a hot fix.
Check at least the return value of the show() function, so calling
store() with stale content is prevented.
Steven said:
"It can cause a deadlock with get_online_cpus() that has been uncovered
by recent cpu hotplug and lockdep changes that Thomas and Peter have
been doing.
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(cpu_hotplug.lock);
lock(slab_mutex);
lock(cpu_hotplug.lock);
lock(slab_mutex);
*** DEADLOCK ***"
Link: http://lkml.kernel.org/r/alpine.DEB.2.20.1705201244540.2255@nanos
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reported-by: Steven Rostedt <rostedt@goodmis.org>
Acked-by: David Rientjes <rientjes@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
| -rw-r--r-- | mm/slub.c | 6 |
1 files changed, 4 insertions, 2 deletions
| @@ -5512,6 +5512,7 @@ static void memcg_propagate_slab_attrs(struct kmem_cache *s) | |||
| 5512 | char mbuf[64]; | 5512 | char mbuf[64]; |
| 5513 | char *buf; | 5513 | char *buf; |
| 5514 | struct slab_attribute *attr = to_slab_attr(slab_attrs[i]); | 5514 | struct slab_attribute *attr = to_slab_attr(slab_attrs[i]); |
| 5515 | ssize_t len; | ||
| 5515 | 5516 | ||
| 5516 | if (!attr || !attr->store || !attr->show) | 5517 | if (!attr || !attr->store || !attr->show) |
| 5517 | continue; | 5518 | continue; |
| @@ -5536,8 +5537,9 @@ static void memcg_propagate_slab_attrs(struct kmem_cache *s) | |||
| 5536 | buf = buffer; | 5537 | buf = buffer; |
| 5537 | } | 5538 | } |
| 5538 | 5539 | ||
| 5539 | attr->show(root_cache, buf); | 5540 | len = attr->show(root_cache, buf); |
| 5540 | attr->store(s, buf, strlen(buf)); | 5541 | if (len > 0) |
| 5542 | attr->store(s, buf, len); | ||
| 5541 | } | 5543 | } |
| 5542 | 5544 | ||
| 5543 | if (buffer) | 5545 | if (buffer) |
