summaryrefslogtreecommitdiff
path: root/include/uapi/linux
diff options
context:
space:
mode:
authorMarc Kleine-Budde <mkl@pengutronix.de>2026-11-03 19:26:49 +0100
committerMarc Kleine-Budde <mkl@pengutronix.de>2026-11-03 19:54:29 +0100
commit493719574532a0630d4a9debd5ce01a8a3fd570d (patch)
tree772e9f7f5c829afdc465cc559dc5cda94b393b43 /include/uapi/linux
parentd3592ab8a1911ea25b6efa3d5b85def73c69f060 (diff)
parentb98179a6e1948c87539f77b387ac785beb5802c6 (diff)
Merge patch series "can: protect the receive lists with a per-device lock"
Oliver Hartkopp <socketcan@hartkopp.net> says: This series fixes a use-after-free in CAN_ISOTP and CAN_BCM that can be triggered when a CAN device is moved to another network namespace while a socket bound to this device is released [1]. Patch 2 makes isotp_bind() check the return values of can_rx_register(), so that bind() does not succeed with missing receivers. Patch 4 copies the CAN_RAW and CAN_ISOTP specific socket options from and to user space outside of lock_sock(), so that a stalled copy can not block raw_notify() waiting for lock_sock() under RTNL. Patches 5 and 6 fix the reset and the calculation of the CAN statistics. Patch 7 removes the pointers from the CAN specific proc output. As it changes the proc output ABI it is not intended for stable and has been moved to the end of the series, so that patches 1-6 can be backported without it. The code of patches 1 and 5-7 is unchanged since v4, apart from the rebase of patch 7 in v12. Only the commit message of patch 1 has been updated after the Sashiko review of v4 to describe the actual NULL pointer dereference in can_rx_unregister() and the CAN_ISOTP path that reaches it. The series is based on net/main. The idea behind patch 3: The receive lists of a CAN device are located in the device's can_ml_priv and travel with the device when it is moved to another network namespace. But they are protected by the per-netns rcvlists_lock, so the lock that protects a device's lists depends on the namespace the caller passes to can_rx_register() and can_rx_unregister(). can_rx_unregister() silently returns when this namespace does not match dev_net(dev) anymore. isotp_release() and bcm_release() leave the netdev notifier list before they can serialize against the notifier. When the device changes its namespace in this window, their filters are not removed and the remaining receivers point to the freed socket or bcm op. Taking RTNL in these release paths is no option, as CAN_RAW already holds RTNL while adding and removing up to CAN_RAW_FILTER_MAX filters per socket, which unprivileged users can trigger repeatedly. Instead, patch 3 protects the receive lists where they are located: A spinlock in struct can_dev_rcv_lists protects the lists of a CAN device (initialized in can_set_ml_priv()) or the 'any' CAN device lists of a namespace (initialized in can_pernet_init()). can_rx_unregister() then finds the subscription independently of the current namespace of the device, which is kept accessible by the tracked device references the protocols already hold. The per-netns rcvlists_lock only protects the receive list statistics, for which CAN_RAW, CAN_BCM and CAN_ISOTP pass the namespace that has been used for can_rx_register(). As a consequence, CAN_RAW and CAN_ISOTP do not need RTNL in bind(), setsockopt() and release() anymore. bind() is serialized against NETDEV_UNREGISTER by publishing the device inside the RCU section of its lookup, as unlist_netdevice() and synchronize_net() precede NETDEV_UNREGISTER both on unregistration and on a namespace change. The notifiers recheck the binding under lock_sock(). As RTNL does not keep NETDEV_DOWN out of bind() anymore, bind() checks IFF_UP after publishing the bound device, with an smp_mb() pair against the notifiers, so a down transition during bind() is still reported with ENETDOWN. Link: https://patch.msgid.link/20261027-can-rx-lock-v12-0-eb5afc2d8b9b@hartkopp.net Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Diffstat (limited to 'include/uapi/linux')
0 files changed, 0 insertions, 0 deletions