From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Subject: [PATCH 1/2] mm/shrinker: do not NULL dereference uninitialized shrinker
Date: Sat, 11 Jul 2015 11:51:54 +0900 [thread overview]
Message-ID: <1436583115-6323-2-git-send-email-sergey.senozhatsky@gmail.com> (raw)
In-Reply-To: <1436583115-6323-1-git-send-email-sergey.senozhatsky@gmail.com>
Consider 'all zeroes' shrinker as 'initialized, but not
registered', and, thus, don't unregister such a shrinker.
This helps to avoid accidental NULL pointer dereferences,
when a zeroed shrinker struct is getting passed to
unregister_shrinker() in error handing path, for example.
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
mm/vmscan.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index c8d8282..cadc8a2 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -254,6 +254,12 @@ EXPORT_SYMBOL(register_shrinker);
*/
void unregister_shrinker(struct shrinker *shrinker)
{
+ /*
+ * All-zeroes is 'initialized, but not registered' shrinker.
+ */
+ if (unlikely(!shrinker->list.next))
+ return;
+
down_write(&shrinker_rwsem);
list_del(&shrinker->list);
up_write(&shrinker_rwsem);
--
2.4.5
--
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>
next prev parent reply other threads:[~2015-07-11 2:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-11 2:51 [PATCH 0/2] mm/shrinker: make unregister_shrinker() less fragile Sergey Senozhatsky
2015-07-11 2:51 ` Sergey Senozhatsky [this message]
2015-07-11 2:51 ` [PATCH 2/2] mm/shrinker: add init_shrinker() function Sergey Senozhatsky
2015-07-11 10:02 ` [PATCH 0/2] mm/shrinker: make unregister_shrinker() less fragile Christoph Hellwig
2015-07-12 2:47 ` Sergey Senozhatsky
2015-07-13 6:33 ` Christoph Hellwig
2015-07-13 6:52 ` Sergey Senozhatsky
2015-07-13 9:03 ` Christoph Hellwig
2015-07-13 9:34 ` Sergey Senozhatsky
2015-07-14 7:17 ` Christoph Hellwig
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=1436583115-6323-2-git-send-email-sergey.senozhatsky@gmail.com \
--to=sergey.senozhatsky@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=sergey.senozhatsky.work@gmail.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).