[PATCH 1/2] mm/shrinker: do not NULL dereference uninitialized shrinker

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

 



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@xxxxxxxxx>
---
 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@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]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]