]> www.infradead.org Git - users/hch/misc.git/commitdiff
ipmi: Fix handling of messages with provided receive message pointer
authorGuenter Roeck <linux@roeck-us.net>
Mon, 6 Oct 2025 20:18:57 +0000 (13:18 -0700)
committerCorey Minyard <corey@minyard.net>
Tue, 7 Oct 2025 11:50:08 +0000 (06:50 -0500)
Prior to commit b52da4054ee0 ("ipmi: Rework user message limit handling"),
i_ipmi_request() used to increase the user reference counter if the receive
message is provided by the caller of IPMI API functions. This is no longer
the case. However, ipmi_free_recv_msg() is still called and decreases the
reference counter. This results in the reference counter reaching zero,
the user data pointer is released, and all kinds of interesting crashes are
seen.

Fix the problem by increasing user reference counter if the receive message
has been provided by the caller.

Fixes: b52da4054ee0 ("ipmi: Rework user message limit handling")
Reported-by: Eric Dumazet <edumazet@google.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Greg Thelen <gthelen@google.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Message-ID: <20251006201857.3433837-1-linux@roeck-us.net>
Signed-off-by: Corey Minyard <corey@minyard.net>
drivers/char/ipmi/ipmi_msghandler.c

index a0b67a35a5f048b1087a18f028cac84a7af46b0d..3700ab4eba3e7ea9dd2eafd72c9a745c67b23685 100644 (file)
@@ -2301,8 +2301,11 @@ static int i_ipmi_request(struct ipmi_user     *user,
        if (supplied_recv) {
                recv_msg = supplied_recv;
                recv_msg->user = user;
-               if (user)
+               if (user) {
                        atomic_inc(&user->nr_msgs);
+                       /* The put happens when the message is freed. */
+                       kref_get(&user->refcount);
+               }
        } else {
                recv_msg = ipmi_alloc_recv_msg(user);
                if (IS_ERR(recv_msg))