Skip to contentSkip to conversation

ipmi: Fix use-after-free of cmd_rcvr in _ipmi_destroy_user()

PATCH In review Yifei Gao 2 participants 2 messages Aug 25 – Aug 26

Subsystems (2)
lore
Share & tools
lore

Yifei Gao

author
#0 lore raw

PATCH 1/1 ipmi: Fix use-after-free of cmd_rcvr in _ipmi_destroy_user()

Commit 9e91f8a6c868 ("ipmi:msghandler: Remove srcu for the ipmi_interfaces list") dropped the synchronize_rcu() between unlinking the command receivers from intf->cmd_rcvrs and freeing them, updating only the comment that explains why the barrier is needed.

The cmd_rcvrs list is still traversed under plain RCU: find_cmd_rcvr() walks it inside rcu_read_lock(), and handle_ipmb_get_msg_cmd() borrows rcvr->user from that lookup within the same read-side section. Without the grace period, _ipmi_destroy_user() can kfree() a cmd_rcvr while a reader still holds a pointer to it, causing a use-after-free.

The rework only made srcu unnecessary for the interfaces list; the cmd_rcvrs list still relies on plain RCU. Restore the synchronize_rcu() before freeing the receivers.

Fixes 9e91f8a6c868 ("ipmi:msghandler: Remove srcu for the ipmi_interfaces list")
Assisted-by Claude:claude-opus-4-8
---
 drivers/char/ipmi/ipmi_msghandler.c | 1 +
 1 file changed, 1 insertion(+)
drivers/char/ipmi/ipmi_msghandler.c +1 -0
index ab4c85f3d6fe..3f4018194df8 100644
@@ -1391,6 +1391,7 @@ static void _ipmi_destroy_user(struct ipmi_user *user)
 		}
 	}
 	mutex_unlock(&intf->cmd_rcvrs_mutex);
+	synchronize_rcu();
 	while (rcvrs) {
 		rcvr = rcvrs;
 		rcvrs = rcvr->next;
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 11 lines · Yifei Gao

Commit 9e91f8a6c868 ("ipmi:msghandler: Remove srcu for the ipmi_interfaces list") dropped the synchronize_rcu() between unlinking the command receivers from intf->cmd_rcvrs and freeing them, updating only the comment that explains why the barrier is needed.

The cmd_rcvrs list is still traversed under plain RCU: find_cmd_rcvr() walks it inside rcu_read_lock(), and handle_ipmb_get_msg_cmd() borrows rcvr->user from that lookup within the same read-side section. Without the grace period, _ipmi_destroy_user() can kfree() a cmd_rcvr while a reader still holds a pointer to it, causing a use-after-free.

Quoted 3 lines

The rework only made srcu unnecessary for the interfaces list; the cmd_rcvrs list still relies on plain RCU. Restore the synchronize_rcu() before freeing the receivers.

Yes, looks good and passes tests, it's in my next tree.

-corey

Quoted 24 lines
Fixes 9e91f8a6c868 ("ipmi:msghandler: Remove srcu for the ipmi_interfaces list")
Assisted-by Claude:claude-opus-4-8
---
 drivers/char/ipmi/ipmi_msghandler.c | 1 +
 1 file changed, 1 insertion(+)
drivers/char/ipmi/ipmi_msghandler.c +1 -0
index ab4c85f3d6fe..3f4018194df8 100644
@@ -1391,6 +1391,7 @@ static void _ipmi_destroy_user(struct ipmi_user *user)
 		}
 	}
 	mutex_unlock(&intf->cmd_rcvrs_mutex);
+	synchronize_rcu();
 	while (rcvrs) {
 		rcvr = rcvrs;
 		rcvrs = rcvr->next;
Signature · 1 line
2.43.0