]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ipmi:msghandler: Fix potential memory corruption in ipmi_create_user()
authorDan Carpenter <dan.carpenter@linaro.org>
Mon, 5 May 2025 14:34:15 +0000 (17:34 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Jul 2025 16:35:12 +0000 (18:35 +0200)
commit fa332f5dc6fc662ad7d3200048772c96b861cf6b upstream.

The "intf" list iterator is an invalid pointer if the correct
"intf->intf_num" is not found.  Calling atomic_dec(&intf->nr_users) on
and invalid pointer will lead to memory corruption.

We don't really need to call atomic_dec() if we haven't called
atomic_add_return() so update the if (intf->in_shutdown) path as well.

Fixes: 8e76741c3d8b ("ipmi: Add a limit on the number of users that may use IPMI")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Message-ID: <aBjMZ8RYrOt6NOgi@stanley.mountain>
Signed-off-by: Corey Minyard <corey@minyard.net>
[ - Dropped change to the `if (intf->in_shutdown)` block since that logic
    doesn't exist yet.
  - Modified out_unlock to release the srcu lock instead of the mutex
    since we don't have the mutex here yet. ]
Signed-off-by: Brendan Jackman <jackmanb@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/char/ipmi/ipmi_msghandler.c

index 186f1fee753403f7b0e0feac76cc7bfd4f20f373..db8f1dadaa9f4f8d1ea9d73884fe6fe9a995a20c 100644 (file)
@@ -1241,7 +1241,7 @@ int ipmi_create_user(unsigned int          if_num,
        }
        /* Not found, return an error */
        rv = -EINVAL;
-       goto out_kfree;
+       goto out_unlock;
 
  found:
        if (atomic_add_return(1, &intf->nr_users) > max_users) {
@@ -1283,6 +1283,7 @@ int ipmi_create_user(unsigned int          if_num,
 
 out_kfree:
        atomic_dec(&intf->nr_users);
+out_unlock:
        srcu_read_unlock(&ipmi_interfaces_srcu, index);
        vfree(new_user);
        return rv;