From: Alexander Polakov Date: Fri, 28 Oct 2016 00:46:27 +0000 (-0700) Subject: mm/list_lru.c: avoid error-path NULL pointer deref X-Git-Tag: v4.9.8~1051^2~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1bc11d70b5db7c6bb1414b283d7f09b1fe1ac0d0;p=platform%2Fkernel%2Flinux-rpi3.git mm/list_lru.c: avoid error-path NULL pointer deref As described in https://bugzilla.kernel.org/show_bug.cgi?id=177821: After some analysis it seems to be that the problem is in alloc_super(). In case list_lru_init_memcg() fails it goes into destroy_super(), which calls list_lru_destroy(). And in list_lru_init() we see that in case memcg_init_list_lru() fails, lru->node is freed, but not set NULL, which then leads list_lru_destroy() to believe it is initialized and call memcg_destroy_list_lru(). memcg_destroy_list_lru() in turn can access lru->node[i].memcg_lrus, which is NULL. [akpm@linux-foundation.org: add comment] Signed-off-by: Alexander Polakov Acked-by: Vladimir Davydov Cc: Al Viro Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/mm/list_lru.c b/mm/list_lru.c index 1d05cb9..234676e 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -554,6 +554,8 @@ int __list_lru_init(struct list_lru *lru, bool memcg_aware, err = memcg_init_list_lru(lru, memcg_aware); if (err) { kfree(lru->node); + /* Do this so a list_lru_destroy() doesn't crash: */ + lru->node = NULL; goto out; }