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

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

 



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@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