ibmphp: Fix module ref count underflow
PATCH 1/1 ibmphp: Fix module ref count underflow
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
ibmphp_core.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/pci/hotplug/ibmphp_core.c +5 -3
@@ -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;
Signature · 4 lines
/**************************************************** * Neil Horman <[email protected]> * Software Engineer, Red Hat ****************************************************/
Quoted 9 lines · Neil Horman
Hey-
I happened to notice that the ibmphp hotplug driver does something
rather silly in its init routine. It purposely callsmodule_putso 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 subsequentmodule_getsto 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.
Quoted 4 lines
Regards
NeilSigned-off-by Neil Horman <[email protected]>
Jesse is the PCI maintainer now, you should send this to him to verify that it goes in.
Feel free to add my:
to this, nice job.
thanks,
greg k-h
Quoted 15 lines · Greg KH
Quoted 9 lines · Neil Horman
Hey-
I happened to notice that the ibmphp hotplug driver does something
rather silly in its init routine. It purposely callsmodule_putso 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 subsequentmodule_getsto 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.Quoted 4 lines
Regards
NeilSigned-off-by Neil Horman <[email protected]>
Quoted 8 lines
Jesse is the PCI maintainer now, you should send this to him to verify that it goes in.
Feel free to add my:
to this, nice job.
Thanks! I've forwarded the patch on to Jesse.
Best
Neil
Quoted 9 lines
thanks,
greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 9 lines · Neil Horman
Hey-
I happened to notice that the ibmphp hotplug driver does something
rather silly in its init routine. It purposely callsmodule_putso 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 subsequentmodule_getsto 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.
Thanks Neil, applied this to my for-linus branch since it sounds potentially serious (but also low risk since who uses ibmphp anymore? :)
Jesse
Quoted 11 lines · Jesse Barnes
Quoted 9 lines · Neil Horman
Hey-
I happened to notice that the ibmphp hotplug driver does something
rather silly in its init routine. It purposely callsmodule_putso 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 subsequentmodule_getsto 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.
Quoted 3 lines
Thanks Neil, applied this to my for-linus branch since it sounds potentially serious (but also low risk since who uses ibmphp anymore? :)
Dang it! Sorry, Jesse. Yes, youre absolutely right, it is low risk. It really just a bit of sillyness all around.
Unfortunately, I took part in the sillyness. The problem was reported to me on RHEL, and I tested there, without checking upstream too closely. As aresult, the patch I gave you is a bit out of date, and won't compile. I've tested the new patch here much more closely. apologies. I informed akpm who was looking at it, but neglected to copy you.
This patch corrects the same problem in that it prevents module unloads in a sane fashion, by not registering an exit routine
ibmphp_core.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/pci/hotplug/ibmphp_core.c +0 -5
@@ -1402,10 +1402,6 @@ 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 ); - exit:return rc;
@@ -1423,4 +1419,3 @@ static void __exit ibmphp_exit(void) }module_init (ibmphp_init); -module_exit (ibmphp_exit);
Quoted 2 lines
Jesse
Signature · 4 lines
/**************************************************** * Neil Horman <[email protected]> * Software Engineer, Red Hat ****************************************************/
Quoted 24 lines · Neil Horman
Quoted 11 lines · Jesse Barnes
Quoted 9 lines · Neil Horman
Hey-
I happened to notice that the ibmphp hotplug driver does something
rather silly in its init routine. It purposely callsmodule_putso 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 subsequentmodule_getsto 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.Quoted 2 lines
Thanks Neil, applied this to my for-linus branch since it sounds potentially serious (but also low risk since who uses ibmphp anymore? :)
Dang it! Sorry, Jesse. Yes, youre absolutely right, it is low risk. It really just a bit of sillyness all around.
Unfortunately, I took part in the sillyness. The problem was reported to me on RHEL, and I tested there, without checking upstream too closely. As aresult, the patch I gave you is a bit out of date, and won't compile. I've tested the new patch here much more closely. apologies. I informed akpm who was looking at it, but neglected to copy you.
Quoted 4 lines
This patch corrects the same problem in that it prevents module unloads in a sane fashion, by not registering an exit routine
Signed-off-by Neil Horman <[email protected]>
Ah was just doing my testing & building now so I would have caught it in a minute. :) I'll replace the patch I have with this one, thanks.
Jesse
Quoted 28 lines · Jesse Barnes
Quoted 27 lines · Neil Horman
Quoted 11 lines · Jesse Barnes
Quoted 9 lines · Neil Horman
Hey-
I happened to notice that the ibmphp hotplug driver does something
rather silly in its init routine. It purposely callsmodule_putso 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 subsequentmodule_getsto 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.Quoted 2 lines
Thanks Neil, applied this to my for-linus branch since it sounds potentially serious (but also low risk since who uses ibmphp anymore? :)
Dang it! Sorry, Jesse. Yes, youre absolutely right, it is low risk. It really just a bit of sillyness all around.
Unfortunately, I took part in the sillyness. The problem was reported to me on RHEL, and I tested there, without checking upstream too closely. As aresult, the patch I gave you is a bit out of date, and won't compile. I've tested the new patch here much more closely. apologies. I informed akpm who was looking at it, but neglected to copy you.
This patch corrects the same problem in that it prevents module unloads in a sane fashion, by not registering an exit routine
Quoted 7 lines
Quoted 1 line
Signed-off-by Neil Horman <[email protected]>Ah was just doing my testing & building now so I would have caught it in a minute. :) I'll replace the patch I have with this one, thanks.
Jesse
Thank you, that matches what Andrew has in his tree. Apologies for the noise Neil