diff mbox series

net: dsa: mv88e6060: prevent crash on an unused port

Message ID 20220811070939.1717146-1-saproj@gmail.com (mailing list archive)
State Accepted
Commit 246bbf2f977ea36aaf41f5d24370fef433250728
Delegated to: Netdev Maintainers
Headers show
Series net: dsa: mv88e6060: prevent crash on an unused port | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 4 maintainers not CCed: edumazet@google.com kuba@kernel.org pabeni@redhat.com andrew@lunn.ch
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Sergei Antonov Aug. 11, 2022, 7:09 a.m. UTC
If the port isn't a CPU port nor a user port, 'cpu_dp'
is a null pointer and a crash happened on dereferencing
it in mv88e6060_setup_port():

[    9.575872] Unable to handle kernel NULL pointer dereference at virtual address 00000014
...
[    9.942216]  mv88e6060_setup from dsa_register_switch+0x814/0xe84
[    9.948616]  dsa_register_switch from mdio_probe+0x2c/0x54
[    9.954433]  mdio_probe from really_probe.part.0+0x98/0x2a0
[    9.960375]  really_probe.part.0 from driver_probe_device+0x30/0x10c
[    9.967029]  driver_probe_device from __device_attach_driver+0xb8/0x13c
[    9.973946]  __device_attach_driver from bus_for_each_drv+0x90/0xe0
[    9.980509]  bus_for_each_drv from __device_attach+0x110/0x184
[    9.986632]  __device_attach from bus_probe_device+0x8c/0x94
[    9.992577]  bus_probe_device from deferred_probe_work_func+0x78/0xa8
[    9.999311]  deferred_probe_work_func from process_one_work+0x290/0x73c
[   10.006292]  process_one_work from worker_thread+0x30/0x4b8
[   10.012155]  worker_thread from kthread+0xd4/0x10c
[   10.017238]  kthread from ret_from_fork+0x14/0x3c

Fixes: 0abfd494deef ("net: dsa: use dedicated CPU port")
CC: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
CC: Florian Fainelli <f.fainelli@gmail.com>
CC: David S. Miller <davem@davemloft.net>
Signed-off-by: Sergei Antonov <saproj@gmail.com>
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
---
 drivers/net/dsa/mv88e6060.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

patchwork-bot+netdevbpf@kernel.org Aug. 13, 2022, 12:50 a.m. UTC | #1
Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 11 Aug 2022 10:09:39 +0300 you wrote:
> If the port isn't a CPU port nor a user port, 'cpu_dp'
> is a null pointer and a crash happened on dereferencing
> it in mv88e6060_setup_port():
> 
> [    9.575872] Unable to handle kernel NULL pointer dereference at virtual address 00000014
> ...
> [    9.942216]  mv88e6060_setup from dsa_register_switch+0x814/0xe84
> [    9.948616]  dsa_register_switch from mdio_probe+0x2c/0x54
> [    9.954433]  mdio_probe from really_probe.part.0+0x98/0x2a0
> [    9.960375]  really_probe.part.0 from driver_probe_device+0x30/0x10c
> [    9.967029]  driver_probe_device from __device_attach_driver+0xb8/0x13c
> [    9.973946]  __device_attach_driver from bus_for_each_drv+0x90/0xe0
> [    9.980509]  bus_for_each_drv from __device_attach+0x110/0x184
> [    9.986632]  __device_attach from bus_probe_device+0x8c/0x94
> [    9.992577]  bus_probe_device from deferred_probe_work_func+0x78/0xa8
> [    9.999311]  deferred_probe_work_func from process_one_work+0x290/0x73c
> [   10.006292]  process_one_work from worker_thread+0x30/0x4b8
> [   10.012155]  worker_thread from kthread+0xd4/0x10c
> [   10.017238]  kthread from ret_from_fork+0x14/0x3c
> 
> [...]

Here is the summary with links:
  - net: dsa: mv88e6060: prevent crash on an unused port
    https://git.kernel.org/netdev/net/c/246bbf2f977e

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/dsa/mv88e6060.c b/drivers/net/dsa/mv88e6060.c
index a4c6eb9a52d0..83dca9179aa0 100644
--- a/drivers/net/dsa/mv88e6060.c
+++ b/drivers/net/dsa/mv88e6060.c
@@ -118,6 +118,9 @@  static int mv88e6060_setup_port(struct mv88e6060_priv *priv, int p)
 	int addr = REG_PORT(p);
 	int ret;
 
+	if (dsa_is_unused_port(priv->ds, p))
+		return 0;
+
 	/* Do not force flow control, disable Ingress and Egress
 	 * Header tagging, disable VLAN tunneling, and set the port
 	 * state to Forwarding.  Additionally, if this is the CPU