linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@kernel.org>
To: Aliaksei Karaliou <akaraliou.dev@gmail.com>
Cc: akpm@linux-foundation.org, hannes@cmpxchg.org,
	hillf.zj@alibaba-inc.com, minchan@kernel.org, linux-mm@kvack.org,
	Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Subject: Re: [PATCH] mm: vmscan: make unregister_shrinker() safer
Date: Mon, 18 Dec 2017 09:49:48 +0100	[thread overview]
Message-ID: <20171218084948.GK16951@dhcp22.suse.cz> (raw)
In-Reply-To: <20171216192937.13549-1-akaraliou.dev@gmail.com>

On Sat 16-12-17 22:29:37, Aliaksei Karaliou wrote:
> 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.

Tetsuo has made it half way to this already [1]. So maybe we should
fold shrinker->nr_deferred = NULL to his patch and finally merge it.

[1] http://lkml.kernel.org/r/1511523385-6433-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp
> 
> 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
> 

-- 
Michal Hocko
SUSE Labs

--
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-18  8:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-16 19:29 Aliaksei Karaliou
2017-12-18  8:49 ` Michal Hocko [this message]
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=20171218084948.GK16951@dhcp22.suse.cz \
    --to=mhocko@kernel.org \
    --cc=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=minchan@kernel.org \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    /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