ipmi: Fix handling of messages with provided receive message pointer
PATCH 1/1 ipmi: Fix handling of messages with provided receive message pointer
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.
--- drivers/char/ipmi/ipmi_msghandler.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/char/ipmi/ipmi_msghandler.c +4 -1
@@ -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))
Signature · 1 line
2.45.2
Corey Minyard
maintainerQuoted 10 lines · Guenter Roeck
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.
Yes, the only interface that uses this that would matter is the watchdog timer, which my tests don't currently cover. I guess I need to add some tests.
Sorry, and thanks for the fix. It's queued for next release.
-corey
Quoted 30 lines
Fixes b52da4054ee0 ("ipmi: Rework user message limit handling")Reported-by Eric Dumazet <[email protected]>Cc Eric Dumazet <[email protected]>Cc Greg Thelen <[email protected]>Signed-off-by Guenter Roeck <[email protected]>--- drivers/char/ipmi/ipmi_msghandler.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/char/ipmi/ipmi_msghandler.c +4
-1@@ -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))Signature · 1 line
2.45.2
Corey Minyard
maintainerQuoted 9 lines · Corey Minyard
Quoted 8 lines · Guenter Roeck
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.
Quoted 8 lines
Quoted 2 lines
Fix the problem by increasing user reference counter if the receive message has been provided by the caller.
Yes, the only interface that uses this that would matter is the watchdog timer, which my tests don't currently cover. I guess I need to add some tests.
Sorry, and thanks for the fix. It's queued for next release.
Sorry, it's queued for this release, 6.18. I'll send it to Linus in a few days.
-corey
Quoted 33 lines
-corey
Quoted 30 lines
Fixes b52da4054ee0 ("ipmi: Rework user message limit handling")Reported-by Eric Dumazet <[email protected]>Cc Eric Dumazet <[email protected]>Cc Greg Thelen <[email protected]>Signed-off-by Guenter Roeck <[email protected]>--- drivers/char/ipmi/ipmi_msghandler.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/char/ipmi/ipmi_msghandler.c +4
-1@@ -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))Signature · 1 line
2.45.2
Quoted 9 lines · Corey Minyard
Quoted 8 lines · Guenter Roeck
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.
Quoted 7 lines
Quoted 2 lines
Fix the problem by increasing user reference counter if the receive message has been provided by the caller.
Yes, the only interface that uses this that would matter is the watchdog timer, which my tests don't currently cover. I guess I need to add some tests.
Yes, that is the one that is crashing. Sorry, I should have mentioned that.
Quoted 2 lines
Sorry, and thanks for the fix. It's queued for next release.
Thanks!
Guenter