public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ibmphp: Fix module ref count underflow
@ 2008-12-10 19:43 Neil Horman
  2008-12-10 22:28 ` Greg KH
  2008-12-16 18:42 ` Jesse Barnes
  0 siblings, 2 replies; 7+ messages in thread
From: Neil Horman @ 2008-12-10 19:43 UTC (permalink / raw)
  To: greg, linux-pci, linux-kernel, akpm; +Cc: nhorman

Hey-
	I happened to notice that the ibmphp hotplug driver does something
rather silly in its init routine.  It purposely calls module_put so as to
underflow its module ref count to avoid being removed from the kernel.  This is
bad practice, and wrong, since it provides a window for subsequent module_gets
to reset the refcount to zero, allowing an unload to race in and cause all sorts
of mysterious panics.  If the module is unsafe to load, it should inform the
kernel as such with a call to __unsafe.  The patch below does that.

Regards
Neil

Signed-off-by: Neil Horman <nhorman@tuxdriver.com>

 ibmphp_core.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)


diff --git a/drivers/pci/hotplug/ibmphp_core.c b/drivers/pci/hotplug/ibmphp_core.c
index c892daa..3706d4e 100644
--- a/drivers/pci/hotplug/ibmphp_core.c
+++ b/drivers/pci/hotplug/ibmphp_core.c
@@ -1402,9 +1402,11 @@ static int __init ibmphp_init(void)
 		goto error;
 	}
 
-	/* lock ourselves into memory with a module 
-	 * count of -1 so that no one can unload us. */
-	module_put(THIS_MODULE);
+	/*
+	 * Its unsafe to unload this module, so tell
+	 * the kernel to avoid inadvertent unloads
+	 */
+	__unsafe(THIS_MODULE);
 
 exit:
 	return rc;
-- 
/****************************************************
 * Neil Horman <nhorman@tuxdriver.com>
 * Software Engineer, Red Hat
 ****************************************************/

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-12-17  1:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-10 19:43 [PATCH] ibmphp: Fix module ref count underflow Neil Horman
2008-12-10 22:28 ` Greg KH
2008-12-11  1:28   ` Neil Horman
2008-12-16 18:42 ` Jesse Barnes
2008-12-16 19:56   ` Neil Horman
2008-12-16 20:52     ` Jesse Barnes
2008-12-17  1:13       ` Neil Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox