Skip to content
Snippets Groups Projects
Commit bedc0149 authored by Qian Cai's avatar Qian Cai Committed by Yang Yingliang
Browse files

mm/slub: fix stack overruns with SLUB_STATS

stable inclusion
from linux-4.19.132
commit 3e632652e3dc186d61d584258becf9ca69ae2f3a

--------------------------------

[ Upstream commit a68ee057 ]

There is no need to copy SLUB_STATS items from root memcg cache to new
memcg cache copies.  Doing so could result in stack overruns because the
store function only accepts 0 to clear the stat and returns an error for
everything else while the show method would print out the whole stat.

Then, the mismatch of the lengths returns from show and store methods
happens in memcg_propagate_slab_attrs():

	else if (root_cache->max_attr_size < ARRAY_SIZE(mbuf))
		buf = mbuf;

max_attr_size is only 2 from slab_attr_store(), then, it uses mbuf[64]
in show_stat() later where a bounch of sprintf() would overrun the stack
variable.  Fix it by always allocating a page of buffer to be used in
show_stat() if SLUB_STATS=y which should only be used for debug purpose.

  # echo 1 > /sys/kernel/slab/fs_ca...
parent b0eb7832
No related branches found
No related tags found
No related merge requests found
......@@ -5605,7 +5605,8 @@ static void memcg_propagate_slab_attrs(struct kmem_cache *s)
*/
if (buffer)
buf = buffer;
else if (root_cache->max_attr_size < ARRAY_SIZE(mbuf))
else if (root_cache->max_attr_size < ARRAY_SIZE(mbuf) &&
!IS_ENABLED(CONFIG_SLUB_STATS))
buf = mbuf;
else {
buffer = (char *) get_zeroed_page(GFP_KERNEL);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment