deepin-kernel/net/mctp
Andrew Jeffery ceaf75d4a7 net: mctp: Ensure keys maintain only one ref to corresponding dev
[ Upstream commit e4f349bd6e ]

mctp_flow_prepare_output() is called in mctp_route_output(), which
places outbound packets onto a given interface. The packet may represent
a message fragment, in which case we provoke an unbalanced reference
count to the underlying device. This causes trouble if we ever attempt
to remove the interface:

    [   48.702195] usb 1-1: USB disconnect, device number 2
    [   58.883056] unregister_netdevice: waiting for mctpusb0 to become free. Usage count = 2
    [   69.022548] unregister_netdevice: waiting for mctpusb0 to become free. Usage count = 2
    [   79.172568] unregister_netdevice: waiting for mctpusb0 to become free. Usage count = 2
    ...

Predicate the invocation of mctp_dev_set_key() in
mctp_flow_prepare_output() on not already having associated the device
with the key. It's not yet realistic to uphold the property that the key
maintains only one device reference earlier in the transmission sequence
as the route (and therefore the device) may not be known at the time the
key is associated with the socket.

Fixes: 67737c4572 ("mctp: Pass flow data & flow release events to drivers")
Acked-by: Jeremy Kerr <jk@codeconstruct.com.au>
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
Link: https://patch.msgid.link/20250508-mctp-dev-refcount-v1-1-d4f965c67bb5@codeconstruct.com.au
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit e4d8a517324c7f11be91bd0203a974f4071667d2)
2025-05-26 10:36:06 +08:00
..
test net: mctp: test: Use correct skb for route input check 2024-12-10 20:40:53 +08:00
Kconfig mctp: Add flow extension to skb 2021-10-29 13:23:51 +01:00
Makefile mctp: Add test utils 2021-10-03 14:35:41 +01:00
af_mctp.c net: mctp: Set SOCK_RCU_FREE 2025-05-09 18:47:32 +08:00
device.c net: mctp: Don't access ifa_index when missing 2025-05-26 10:36:06 +08:00
neigh.c mctp: Handle error of rtnl_register_module(). 2024-12-10 20:42:48 +08:00
route.c net: mctp: Ensure keys maintain only one ref to corresponding dev 2025-05-26 10:36:06 +08:00