linux/drivers
Vladimir Oltean bfd264fbbb net: dsa: sja1105: protect link replay helpers against NULL phylink instance
There is a crash when unbinding the sja1105 driver under special
circumstances:

Unable to handle kernel NULL pointer dereference at virtual address 0000000000000030
Call trace:
phylink_run_resolve_and_disable+0x10/0x90
sja1105_static_config_reload+0xc0/0x410
sja1105_vlan_filtering+0x100/0x140
dsa_port_vlan_filtering+0x13c/0x368
dsa_port_reset_vlan_filtering.isra.0+0xe8/0x198
dsa_port_bridge_leave+0x130/0x248
dsa_user_changeupper.part.0+0x74/0x158
dsa_user_netdevice_event+0x50c/0xa50
notifier_call_chain+0x78/0x148
raw_notifier_call_chain+0x20/0x38
call_netdevice_notifiers_info+0x58/0xa8
__netdev_upper_dev_unlink+0xac/0x220
netdev_upper_dev_unlink+0x38/0x70
del_nbp+0x1a4/0x320
br_del_if+0x3c/0xd8
br_device_event+0xf8/0x2d8
notifier_call_chain+0x78/0x148
raw_notifier_call_chain+0x20/0x38
call_netdevice_notifiers_info+0x58/0xa8
unregister_netdevice_many_notify+0x314/0x848
unregister_netdevice_queue+0xe8/0xf8
dsa_user_destroy+0x50/0xa8
dsa_port_teardown+0x80/0x98
dsa_switch_teardown_ports+0x4c/0xb8
dsa_switch_deinit+0x94/0xb8
dsa_switch_put_tree+0x2c/0xc0
dsa_unregister_switch+0x38/0x60
sja1105_remove+0x24/0x40
spi_remove+0x38/0x60
device_remove+0x54/0x90
device_release_driver_internal+0x1d4/0x230
device_driver_detach+0x20/0x38
unbind_store+0xbc/0xc8
---[ end trace 0000000000000000 ]---

which requires an explanation.

When a port offloads a bridge, the switch must be reset to change
the VLAN awareness state (the SJA1105_VLAN_FILTERING reason for
sja1105_static_config_reload()). When the port leaves a VLAN-aware
bridge, it must also be reset for the same reason: it is returning
to operation as a VLAN-unaware standalone port.

sja1105_static_config_reload() triggers the phylink link replay helpers.

Because sja1105 is a switch, it has multiple user ports. During unbind,
ports are torn down one by one in dsa_switch_teardown_ports() ->
dsa_port_teardown() -> dsa_user_destroy().

The crash happens when the first user port is not part of the VLAN-aware
bridge, but any other user port is.

Tearing down the first user port causes phylink_destroy() to be called
on dp->pl, and this pointer to be set to NULL. Then, when the second
user port is torn down, this was offloading a VLAN-aware bridge port, so
indirectly it will trigger sja1105_static_config_reload().

The latter function iterates using dsa_switch_for_each_available_port(),
and unconditionally dereferences dp->pl, including for the
aforementioned torn down previous port, and passes that to phylink.
This is where the NULL pointer is coming from.

There are multiple levels at which this could be avoided:
- add an "if (dp->pl)" in sja1105_static_config_reload()
- make the phylink replay helpers NULL-tolerant
- mark ports as DSA_PORT_TYPE_UNUSED after dsa_port_phylink_destroy()
  has run, such that subsequent dsa_switch_for_each_available_port()
  iterations skip them
- disconnect the entire switch at once from switchdev and
  NETDEV_CHANGEUPPER events while unbinding, not just port by port,
  likely using a "ds->unbinding = true" mechanism or similar

however options 3 and 4 are quite heavy and might have side effects.
Although 2 allows to keep the driver simpler, the phylink API it not
NULL-tolerant in general and is not responsible for the NULL pointer
(this is something done by dsa_port_phylink_destroy()). So I went
with 1.

Functionally speaking, skipping the replay helpers for ports without
a phylink instance is fine, because that only happens during driver
removal (an operation which cannot be cancelled). The ports are not
required to work (although they probably still will - untested
assumption - as long as we don't overwrite the last port speed with
SJA1105_SPEED_AUTO).

Fixes: 0b2edc531e ("net: dsa: sja1105: let phylink help with the replay of link callbacks")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/20260218160551.194782-1-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2026-02-19 14:55:57 -08:00
..
accel Char/Misc/IIO driver changes for 7.0-rc1 2026-02-17 09:11:04 -08:00
accessibility
acpi More ACPI support updates for 7.0-rc1 2026-02-18 14:28:57 -08:00
amba
android Char/Misc/IIO driver changes for 7.0-rc1 2026-02-17 09:11:04 -08:00
ata ATA changes for 6.20 2026-02-12 17:12:43 -08:00
atm Including fixes from Netfilter. 2026-02-19 10:39:08 -08:00
auxdisplay mm.git review status for linus..mm-nonmm-stable 2026-02-12 12:13:01 -08:00
base More power management updates for 7.0-rc1 2026-02-18 14:11:47 -08:00
bcma
block block-7.0-20260216 2026-02-17 08:48:45 -08:00
bluetooth TTY / Serial driver updates for 7.0-rc1 2026-02-17 09:30:52 -08:00
bus Char/Misc/IIO driver changes for 7.0-rc1 2026-02-17 09:11:04 -08:00
cache
cdrom
cdx cdx: Use mutex guard to simplify error handling 2026-02-03 20:58:13 -06:00
char mm.git review status for linus..mm-stable 2026-02-18 20:50:32 -08:00
clk cleanups and fixes 2026-02-16 09:30:44 -08:00
clocksource - A nice cleanup to the paravirt code containing a unification of the paravirt 2026-02-10 19:01:45 -08:00
comedi Char/Misc/IIO driver changes for 7.0-rc1 2026-02-17 09:11:04 -08:00
connector
counter
cpufreq Devicetree updates for v7.0: 2026-02-11 18:27:08 -08:00
cpuidle More power management updates for 7.0-rc1 2026-02-18 14:11:47 -08:00
crypto platform-drivers-x86 for v7.0-1 2026-02-13 15:39:15 -08:00
cxl cxl changes for v7.0 2026-02-12 16:33:05 -08:00
dax mm.git review status for linus..mm-stable 2026-02-18 20:50:32 -08:00
dca
devfreq
dibs
dio
dma dmaengine updates for v7.0 2026-02-17 11:47:17 -08:00
dma-buf VFIO updates for v7.0-rc1 2026-02-12 15:52:39 -08:00
dpll dpll: zl3073x: Fix ref frequency setting 2026-02-17 17:06:51 -08:00
edac - Remove two drivers for obsolete hardware: i82443bxgx_edac and r82600_edac 2026-02-10 18:14:36 -08:00
eisa
extcon
firewire SCSI misc on 20260212 2026-02-12 15:43:02 -08:00
firmware Char/Misc/IIO driver changes for 7.0-rc1 2026-02-17 09:11:04 -08:00
fpga
fsi
fwctl
gnss
gpib
gpio virtio,vhost,vdpa: features, fixes 2026-02-13 12:02:18 -08:00
gpu mm.git review status for linus..mm-stable 2026-02-18 20:50:32 -08:00
greybus
hid Input updates for v7.0-rc0 2026-02-15 08:24:19 -08:00
hsi
hte
hv drivers: hv: vmbus_drv: Remove reference to hpyerv_fb 2026-02-14 11:07:12 +01:00
hwmon mm.git review status for linus..mm-nonmm-stable 2026-02-12 12:13:01 -08:00
hwspinlock soc: driver updates for 7.0 2026-02-10 20:45:30 -08:00
hwtracing Char/Misc/IIO driver changes for 7.0-rc1 2026-02-17 09:11:04 -08:00
i2c Char/Misc/IIO driver changes for 7.0-rc1 2026-02-17 09:11:04 -08:00
i3c
idle
iio IIO: New device support, features and cleanup for the 6.20/7.0 cycle. 2026-02-02 17:08:30 +01:00
infiniband RDMA v7.0 merge window 2026-02-12 17:05:20 -08:00
input Input updates for v7.0-rc0 2026-02-15 08:24:19 -08:00
interconnect
iommu RISC-V updates for v7.0 2026-02-12 19:17:44 -08:00
ipack
irqchip cleanups and fixes 2026-02-16 09:30:44 -08:00
isdn
leds LEDS for v6.20 2026-02-16 11:15:19 -08:00
macintosh
mailbox soc: driver updates for 7.0 2026-02-10 20:45:30 -08:00
mcb
md block-7.0-20260216 2026-02-17 08:48:45 -08:00
media mm.git review status for linus..mm-nonmm-stable 2026-02-12 12:13:01 -08:00
memory
memstick
message
mfd MFD for v6.20 2026-02-16 11:05:44 -08:00
misc Char/Misc/IIO driver changes for 7.0-rc1 2026-02-17 09:11:04 -08:00
mmc cleanups and fixes 2026-02-16 09:30:44 -08:00
most
mtd * MTD 2026-02-13 15:06:58 -08:00
mux mux: mmio: fix regmap leak on probe failure 2026-02-05 17:07:37 +01:00
net net: dsa: sja1105: protect link replay helpers against NULL phylink instance 2026-02-19 14:55:57 -08:00
nfc nfc: nxp-nci: remove interrupt trigger type 2026-02-06 20:54:50 -08:00
ntb
nubus
nvdimm nvdimm: virtio_pmem: serialize flush requests 2026-02-04 13:16:40 -06:00
nvme block-7.0-20260216 2026-02-17 08:48:45 -08:00
nvmem Char/Misc/IIO driver changes for 7.0-rc1 2026-02-17 09:11:04 -08:00
of mm.git review status for linus..mm-nonmm-stable 2026-02-12 12:13:01 -08:00
opp
parisc parisc architecture fixes and updates for kernel v7.0-rc1: 2026-02-10 21:42:10 -08:00
parport
pci cxl changes for v7.0 2026-02-12 16:33:05 -08:00
pcmcia
peci
perf perf/arm-cmn: Reject unsupported hardware configurations 2026-02-03 19:43:52 +00:00
phy phy-for-7.0 2026-02-17 11:40:04 -08:00
pinctrl Pin control changes for the v7.0 kernel cycle: 2026-02-16 09:35:24 -08:00
platform USB / Thunderbolt changes for 7.0-rc1 2026-02-17 09:36:43 -08:00
pmdomain pmdomain providers: 2026-02-06 10:10:39 -08:00
pnp
power power supply and reset changes for the 7.0 series 2026-02-12 18:24:37 -08:00
powercap powercap: intel_rapl_tpmi: Remove FW_BUG from invalid version check 2026-02-12 14:49:14 +01:00
pps
ps3
ptp mm.git review status for linus..mm-nonmm-stable 2026-02-12 12:13:01 -08:00
pwm Driver core changes for 7.0-rc1 2026-02-11 17:43:59 -08:00
rapidio rapidio: replace rio_free_net() with kfree() in rio_scan_alloc_net() 2026-01-31 16:16:07 -08:00
ras - Remove two drivers for obsolete hardware: i82443bxgx_edac and r82600_edac 2026-02-10 18:14:36 -08:00
regulator MFD for v6.20 2026-02-16 11:05:44 -08:00
remoteproc remoteproc: imx_rproc: Fix invalid loaded resource table detection 2026-02-03 09:23:12 -07:00
resctrl
reset
rpmsg
rtc cleanups and fixes 2026-02-16 09:30:44 -08:00
s390 SCSI misc on 20260212 2026-02-12 15:43:02 -08:00
sbus
scsi virtio,vhost,vdpa: features, fixes 2026-02-13 12:02:18 -08:00
sh
siox
slimbus
soc phy-for-7.0 2026-02-17 11:40:04 -08:00
soundwire soundwire updates for 7.0 2026-02-17 10:07:13 -08:00
spi Char/Misc/IIO driver changes for 7.0-rc1 2026-02-17 09:11:04 -08:00
spmi
ssb
staging Staging driver updates for 7.0-rc1 2026-02-17 09:20:58 -08:00
target SCSI misc on 20260212 2026-02-12 15:43:02 -08:00
tc
tee
thermal Additional thermal control update for 7.0-rc1 2026-02-18 14:33:18 -08:00
thunderbolt USB / Thunderbolt changes for 7.0-rc1 2026-02-17 09:36:43 -08:00
tty TTY / Serial driver updates for 7.0-rc1 2026-02-17 09:30:52 -08:00
ufs SCSI misc on 20260212 2026-02-12 15:43:02 -08:00
uio
usb USB / Thunderbolt changes for 7.0-rc1 2026-02-17 09:36:43 -08:00
vdpa vduse: avoid adding implicit padding 2026-02-09 12:21:32 -05:00
vfio VFIO updates for v7.0-rc1 2026-02-12 15:52:39 -08:00
vhost virtio,vhost,vdpa: features, fixes 2026-02-13 12:02:18 -08:00
video Backlight for v6.20 2026-02-16 11:10:33 -08:00
virt tsm for 7.0 2026-02-15 10:20:37 -08:00
virtio virtio,vhost,vdpa: features, fixes 2026-02-13 12:02:18 -08:00
w1
watchdog linux-watchdog 6.20-rc1 tag 2026-02-16 12:21:22 -08:00
xen - A nice cleanup to the paravirt code containing a unification of the paravirt 2026-02-10 19:01:45 -08:00
zorro
Kconfig
Makefile phy: enter drivers/phy/Makefile even without CONFIG_GENERIC_PHY 2026-02-04 20:45:26 +05:30