]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commit
mm: memcg/slab: fix use after free in obj_cgroup_charge
authorMuchun Song <songmuchun@bytedance.com>
Tue, 15 Dec 2020 03:06:35 +0000 (19:06 -0800)
committerPaolo Pisati <paolo.pisati@canonical.com>
Mon, 4 Jan 2021 15:37:36 +0000 (16:37 +0100)
commit24329e51357b0c9ee7b9a3597f7bef8bc5671ad8
tree4b2fb2966ee9b3cbc6b7f7e8b7df6fa05f437d2e
parent94bf56fe085a60d4a3ec3206c01b5ce3269d382a
mm: memcg/slab: fix use after free in obj_cgroup_charge

BugLink: https://bugs.launchpad.net/bugs/1910111
[ Upstream commit eefbfa7fd678805b38a46293e78543f98f353d3e ]

The rcu_read_lock/unlock only can guarantee that the memcg will not be
freed, but it cannot guarantee the success of css_get to memcg.

If the whole process of a cgroup offlining is completed between reading a
objcg->memcg pointer and bumping the css reference on another CPU, and
there are exactly 0 external references to this memory cgroup (how we get
to the obj_cgroup_charge() then?), css_get() can change the ref counter
from 0 back to 1.

Link: https://lkml.kernel.org/r/20201028035013.99711-2-songmuchun@bytedance.com
Fixes: bf4f059954dc ("mm: memcg/slab: obj_cgroup API")
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Acked-by: Roman Gushchin <guro@fb.com>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Yafang Shao <laoar.shao@gmail.com>
Cc: Chris Down <chris@chrisdown.name>
Cc: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
mm/memcontrol.c