Remove redundant cleanup in ipmi_register_smi
PATCH 1/1 Remove redundant cleanup in ipmi_register_smi
When ipmi_register_smi fails, it performs a small cleanup routine before returning its error value. In try_smi_init, on the condition that ipmi_register_smi fails, ipmi_unregister_smi is called. ipmi_unregister_smi performs the same cleanup routine as ipmi_register_smi. This results in a kernel NULL pointer dereference. Removing the cleanup routine in ipmi_register_smi results in proper cleanup of a ipmi_register_smi failure.
--- drivers/char/ipmi/ipmi_msghandler.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/char/ipmi/ipmi_msghandler.c +5 -5
@@ -3395,12 +3395,12 @@ int ipmi_register_smi(const struct ipmi_smi_handlers *handlers, out:if (rv) { -ipmi_bmc_unregister (intf); -list_del_rcu (&intf->link); +/* +* ipmi_unregister_smi must be called to clean up after +* failure. We unlock the mutex to allow ipmi_unregister_smi +* to lock it and perform cleanup. +*/ mutex_unlock (&ipmi_interfaces_mutex); -synchronize_srcu (&ipmi_interfaces_srcu); -cleanup_srcu_struct (&intf->users_srcu); -kref_put (&intf->refcount, intf_free); }else {/* * Keep memory order straight for RCU readers. Make
Signature · 1 line
2.12.3
Quoted 6 lines · Justin Ernst
When
ipmi_register_smifails, it performs a small cleanup routine before returning its error value. Intry_smi_init, on the condition thatipmi_register_smifails,ipmi_unregister_smiis called.ipmi_unregister_smiperforms the same cleanup routine asipmi_register_smi. This results in a kernel NULL pointer dereference. Removing the cleanup routine inipmi_register_smiresults in proper cleanup of aipmi_register_smifailure.
This is almost certainly wrong. If ipmi_register_smi() fails, the calling code shouldn't call ipmi_unregister_smi().
However, I think I know what is going wrong. ipmi_register_smi() can fail after the interface is initialized, if so the registering code will think it is registered and call ipmi_unregister_smi() on a failure. I'll send a patch for this.
-corey
Quoted 36 lines
Cc Corey Minyard <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Jeremy Kerr <[email protected]>Cc Russ Anderson <[email protected]>Acked-by Andrew Banman <[email protected]>Signed-off-by Justin Ernst <[email protected]>--- drivers/char/ipmi/ipmi_msghandler.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/char/ipmi/ipmi_msghandler.c +5
-5@@ -3395,12 +3395,12 @@ int ipmi_register_smi(const struct ipmi_smi_handlers *handlers, out:if (rv) { -ipmi_bmc_unregister (intf); -list_del_rcu (&intf->link); +/* +* ipmi_unregister_smi must be called to clean up after +* failure. We unlock the mutex to allow ipmi_unregister_smi +* to lock it and perform cleanup. +*/ mutex_unlock (&ipmi_interfaces_mutex); -synchronize_srcu (&ipmi_interfaces_srcu); -cleanup_srcu_struct (&intf->users_srcu); -kref_put (&intf->refcount, intf_free); }else {/* * Keep memory order straight for RCU readers. Make
Quoted 24 lines
-----Original Message-----
From: Corey Minyard [mailto:[email protected]]
Sent: Wednesday, August 22, 2018 11:28 AM
To: Ernst, Justin <[email protected]>; Corey Minyard <[email protected]>
Cc: Arnd Bergmann <[email protected]>; Greg Kroah-Hartman <[email protected]>; Jeremy Kerr <[email protected]>; openipmi- [email protected]; [email protected]; Anderson, Russ <[email protected]>
Subject: Re: [PATCH] Remove redundant cleanup inipmi_register_smiQuoted 6 lines · Justin Ernst
When
ipmi_register_smifails, it performs a small cleanup routine before returning its error value. Intry_smi_init, on the condition thatipmi_register_smifails,ipmi_unregister_smiis called.ipmi_unregister_smiperforms the same cleanup routine asipmi_register_smi. This results in a kernel NULL pointer dereference. Removing the cleanup routine inipmi_register_smiresults in propercleanup of a
ipmi_register_smifailure.This is almost certainly wrong. If
ipmi_register_smi()fails, the calling code shouldn't callipmi_unregister_smi().
Quoted 6 lines
However, I think I know what is going wrong.
ipmi_register_smi()can fail after the interface is initialized, if so the registering code will think it is registered and callipmi_unregister_smi()on a failure. I'll send a patch for this.-corey
Thanks for the reply Corey. I agree with what you have stated. I'll be watching for the patch. -Justin
Quoted 40 lines
Quoted 39 lines
Cc Corey Minyard <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Jeremy Kerr <[email protected]>Cc Russ Anderson <[email protected]>Acked-by Andrew Banman <[email protected]>Signed-off-by Justin Ernst <[email protected]>--- drivers/char/ipmi/ipmi_msghandler.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/char/ipmi/ipmi_msghandler.c +5
-5@@ -3395,12 +3395,12 @@ int ipmi_register_smi(const struct ipmi_smi_handlers *handlers, out: if (rv) { -ipmi_bmc_unregister (intf ); -list_del_rcu (&intf->link); +/* +* ipmi_unregister_smi must be called to clean up after +* failure. We unlock the mutex to allow ipmi_unregister_smi +* to lock it and perform cleanup. +*/ mutex_unlock (&ipmi_interfaces_mutex); -synchronize_srcu (&ipmi_interfaces_srcu); -cleanup_srcu_struct (&intf->users_srcu); -kref_put (&intf->refcount, intf_free); } else {/* * Keep memory order straight for RCU readers. Make