ipmi: fix use after free in _ipmi_destroy_user()
authorDan Carpenter <error27@gmail.com>
Tue, 15 Nov 2022 13:17:43 +0000 (16:17 +0300)
committerCorey Minyard <cminyard@mvista.com>
Tue, 15 Nov 2022 14:14:29 +0000 (08:14 -0600)
The intf_free() function frees the "intf" pointer so we cannot
dereference it again on the next line.

Fixes: cbb79863fc31 ("ipmi: Don't allow device module unload when in use")
Signed-off-by: Dan Carpenter <error27@gmail.com>
Message-Id: <Y3M8xa1drZv4CToE@kili>
Cc: <stable@vger.kernel.org> # 5.5+
Signed-off-by: Corey Minyard <cminyard@mvista.com>
drivers/char/ipmi/ipmi_msghandler.c

index f6b8ca6df9b533f970bc58abcdee49ec3a730e2e..186f1fee753403f7b0e0feac76cc7bfd4f20f373 100644 (file)
@@ -1330,6 +1330,7 @@ static void _ipmi_destroy_user(struct ipmi_user *user)
        unsigned long    flags;
        struct cmd_rcvr  *rcvr;
        struct cmd_rcvr  *rcvrs = NULL;
+       struct module    *owner;
 
        if (!acquire_ipmi_user(user, &i)) {
                /*
@@ -1392,8 +1393,9 @@ static void _ipmi_destroy_user(struct ipmi_user *user)
                kfree(rcvr);
        }
 
+       owner = intf->owner;
        kref_put(&intf->refcount, intf_free);
-       module_put(intf->owner);
+       module_put(owner);
 }
 
 int ipmi_destroy_user(struct ipmi_user *user)