Re: [PATCH] mm: vmscan: make unregister_shrinker() safer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/18/2017 11:49 AM, Michal Hocko wrote:

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@xxxxxxxxxxxxxxxxxxx
Yeah, no problem from my side.
I'm sorry, it seems that I haven't done enough research to realize that someone is already
looking at that place.


The only my concern/question is whether we should also add some paranoid stuff in that
extra branch (check that list is empty for example) or not.
Signed-off-by: Aliaksei Karaliou <akaraliou.dev@xxxxxxxxx>
---
  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@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]
  Powered by Linux