Skip to contentSkip to conversation

ipmi:ssif: Clean up kthread on errors

PATCH New Corey Minyard 1 participant 1 message Apr 13

Subsystems (2)
lore
Share & tools
lore

Corey Minyard

author maintainer
#0 lore raw

PATCH 1/1 ipmi:ssif: Clean up kthread on errors

If an error occurs after the ssif kthread is created, but before the main IPMI code starts the ssif interface, the ssif kthread will not be stopped.

So make sure the kthread is stopped on an error condition if it is running.

Fixes 259307074bfc ("ipmi: Add SMBus interface driver (SSIF)")

---
This should fix the issue, here for you to review and/or test. I added code to make the issue happen, and this fixes it. I added:

        if (ssif_info->thread) {
                rv = -ENODEV;
                goto out_remove_attr;
        }

right before the call to ipmi_register_smi().

In some cases it's possible that ipmi_register_smi() will call ssif_shutdown(), so I had to account for that case. That was the only subtle thing I found.

You reported this as a security defect, and I'm not 100% sure it's really that big a deal. It would be just about impossible to exploit this. But, stranger things have happened, I suppose.

Anyway, thanks again, I really appreciate reports like this.

 drivers/char/ipmi/ipmi_ssif.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/char/ipmi/ipmi_ssif.c +12 -1
index ce918fe987c6..b49500a1bd36 100644
@@ -1268,8 +1268,10 @@ static void shutdown_ssif(void *send_info)
 	ssif_info->stopping = true;
 	timer_delete_sync(&ssif_info->watch_timer);
 	timer_delete_sync(&ssif_info->retry_timer);
-	if (ssif_info->thread)
+	if (ssif_info->thread) {
 		kthread_stop(ssif_info->thread);
+		ssif_info->thread = NULL;
+	}
 }
 
 static void ssif_remove(struct i2c_client *client)
@@ -1912,6 +1914,15 @@ static int ssif_probe(struct i2c_client *client)
 
  out:
 	if (rv) {
+		/*
+		 * If ipmi_register_smi() starts the interface, it will
+		 * call shutdown and that will free the thread and set
+		 * it to NULL.  Otherwise it must be freed here.
+		 */
+		if (ssif_info->thread) {
+			kthread_stop(ssif_info->thread);
+			ssif_info->thread = NULL;
+		}
 		if (addr_info)
 			addr_info->client = NULL;
 
Signature · 1 line
2.43.0