linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Aliaksei Karaliou <akaraliou.dev@gmail.com>
To: akpm@linux-foundation.org, mhocko@suse.com, hannes@cmpxchg.org,
	hillf.zj@alibaba-inc.com, minchan@kernel.org
Cc: Aliaksei Karaliou <akaraliou.dev@gmail.com>, linux-mm@kvack.org
Subject: [PATCH] mm: vmscan: make unregister_shrinker() safer
Date: Sat, 16 Dec 2017 22:29:37 +0300	[thread overview]
Message-ID: <20171216192937.13549-1-akaraliou.dev@gmail.com> (raw)

unregister_shrinker() does not have any sanitizing inside so
calling it twice will oops because of double free attempt or so.
This patch makes unregister_shrinker() safer and allows calling
it on resource freeing path without explicit knowledge of whether
shrinker was successfully registered or not.

Signed-off-by: Aliaksei Karaliou <akaraliou.dev@gmail.com>
---
 mm/vmscan.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 65c4fa26abfa..7cb56db5e9ca 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -281,10 +281,14 @@ EXPORT_SYMBOL(register_shrinker);
  */
 void unregister_shrinker(struct shrinker *shrinker)
 {
+	if (!shrinker->nr_deferred)
+		return;
+
 	down_write(&shrinker_rwsem);
 	list_del(&shrinker->list);
 	up_write(&shrinker_rwsem);
 	kfree(shrinker->nr_deferred);
+	shrinker->nr_deferred = NULL;
 }
 EXPORT_SYMBOL(unregister_shrinker);
 
-- 
2.11.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

             reply	other threads:[~2017-12-16 19:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-16 19:29 Aliaksei Karaliou [this message]
2017-12-18  8:49 ` Michal Hocko
2017-12-18 18:34   ` ak
2017-12-18 20:46     ` Michal Hocko

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=20171216192937.13549-1-akaraliou.dev@gmail.com \
    --to=akaraliou.dev@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=hillf.zj@alibaba-inc.com \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=minchan@kernel.org \
    /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