linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kirill Tkhai <ktkhai@virtuozzo.com>
To: syzbot <syzbot+d5f648a1bfe15678786b@syzkaller.appspotmail.com>,
	akpm@linux-foundation.org, aryabinin@virtuozzo.com,
	hannes@cmpxchg.org, jbacik@fb.com, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, mgorman@techsingularity.net, mhocko@suse.com,
	penguin-kernel@I-love.SAKURA.ne.jp, shakeelb@google.com,
	syzkaller-bugs@googlegroups.com, ying.huang@intel.com
Subject: [PATCH] mm: Check shrinker is memcg-aware in register_shrinker_prepared()
Date: Mon, 20 Aug 2018 16:28:45 +0300	[thread overview]
Message-ID: <8ff8a793-8211-713a-4ed9-d6e52390c2fc@virtuozzo.com> (raw)
In-Reply-To: <0000000000003427e80573bcde5c@google.com>

There is a sad BUG introduced in patch adding SHRINKER_REGISTERING.
shrinker_idr business is only for memcg-aware shrinkers. Only
such type of shrinkers have id and they must be finaly installed
via idr_replace() in this function. For !memcg-aware shrinkers
we never initialize shrinker->id field.

But there are all types of shrinkers passed to idr_replace(),
and every !memcg-aware shrinker with random ID (most probably,
its id is 0) replaces memcg-aware shrinker pointed by the ID
in IDR.

This patch fixes the problem.
    
Reported-by: syzbot+d5f648a1bfe15678786b@syzkaller.appspotmail.com
Fixes: 7e010df53c80 "mm: use special value SHRINKER_REGISTERING instead of list_empty() check"
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 4375b1e9bd56..3c6e2bfee427 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -408,7 +408,8 @@ void register_shrinker_prepared(struct shrinker *shrinker)
 	down_write(&shrinker_rwsem);
 	list_add_tail(&shrinker->list, &shrinker_list);
 #ifdef CONFIG_MEMCG_KMEM
-	idr_replace(&shrinker_idr, shrinker, shrinker->id);
+	if (shrinker->flags & SHRINKER_MEMCG_AWARE)
+		idr_replace(&shrinker_idr, shrinker, shrinker->id);
 #endif
 	up_write(&shrinker_rwsem);
 }


      reply	other threads:[~2018-08-20 13:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-18 22:05 KASAN: use-after-free Read in do_shrink_slab syzbot
2018-08-20 13:28 ` Kirill Tkhai [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8ff8a793-8211-713a-4ed9-d6e52390c2fc@virtuozzo.com \
    --to=ktkhai@virtuozzo.com \
    --cc=akpm@linux-foundation.org \
    --cc=aryabinin@virtuozzo.com \
    --cc=hannes@cmpxchg.org \
    --cc=jbacik@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@suse.com \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=shakeelb@google.com \
    --cc=syzbot+d5f648a1bfe15678786b@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=ying.huang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).