2013-04-01 02:39:30

by Zefan Li

[permalink] [raw]
Subject: [PATCH] memcg: avoid accessing memcg after releasing reference

This might cause use-after-free bug.

Signed-off-by: Li Zefan <[email protected]>
---

found when reading the code.

---
mm/memcontrol.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 8ec501c..6391046 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3186,12 +3186,12 @@ void memcg_release_cache(struct kmem_cache *s)

root = s->memcg_params->root_cache;
root->memcg_params->memcg_caches[id] = NULL;
- mem_cgroup_put(memcg);

mutex_lock(&memcg->slab_caches_mutex);
list_del(&s->memcg_params->list);
mutex_unlock(&memcg->slab_caches_mutex);

+ mem_cgroup_put(memcg);
out:
kfree(s->memcg_params);
}
--
1.8.0.2


2013-04-01 05:05:47

by Kamezawa Hiroyuki

[permalink] [raw]
Subject: Re: [PATCH] memcg: avoid accessing memcg after releasing reference

(2013/04/01 11:39), Li Zefan wrote:
> This might cause use-after-free bug.
>
> Signed-off-by: Li Zefan <[email protected]>

Thank you.

Acked-by: KAMEZAWA Hiroyuki <[email protected]>

2013-04-01 09:39:32

by Michal Hocko

[permalink] [raw]
Subject: Re: [PATCH] memcg: avoid accessing memcg after releasing reference

On Mon 01-04-13 10:39:00, Li Zefan wrote:
> This might cause use-after-free bug.
>
> Signed-off-by: Li Zefan <[email protected]>

Acked-by: Michal Hocko <[email protected]>

> ---
>
> found when reading the code.
>
> ---
> mm/memcontrol.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 8ec501c..6391046 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3186,12 +3186,12 @@ void memcg_release_cache(struct kmem_cache *s)
>
> root = s->memcg_params->root_cache;
> root->memcg_params->memcg_caches[id] = NULL;
> - mem_cgroup_put(memcg);
>
> mutex_lock(&memcg->slab_caches_mutex);
> list_del(&s->memcg_params->list);
> mutex_unlock(&memcg->slab_caches_mutex);
>
> + mem_cgroup_put(memcg);
> out:
> kfree(s->memcg_params);
> }
> --
> 1.8.0.2

--
Michal Hocko
SUSE Labs