diff mbox series

[net] net: dsa: qca8k: fix NULL pointer dereference for of_device_get_match_data

Message ID 20220904215319.13070-1-ansuelsmth@gmail.com (mailing list archive)
State Accepted
Commit 42b998d4aa59b9dea51665e4f3be1d733c47e2bf
Delegated to: Netdev Maintainers
Headers show
Series [net] net: dsa: qca8k: fix NULL pointer dereference for of_device_get_match_data | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
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 success CCed 10 of 10 maintainers
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, 10 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Christian Marangi Sept. 4, 2022, 9:53 p.m. UTC
of_device_get_match_data is called on priv->dev before priv->dev is
actually set. Move of_device_get_match_data after priv->dev is correctly
set to fix this kernel panic.

Fixes: 3bb0844e7bcd ("net: dsa: qca8k: cache match data to speed up access")
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/net/dsa/qca/qca8k-8xxx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Vladimir Oltean Sept. 5, 2022, 4:50 p.m. UTC | #1
On Sun, Sep 04, 2022 at 11:53:19PM +0200, Christian Marangi wrote:
> of_device_get_match_data is called on priv->dev before priv->dev is
> actually set. Move of_device_get_match_data after priv->dev is correctly
> set to fix this kernel panic.
> 
> Fixes: 3bb0844e7bcd ("net: dsa: qca8k: cache match data to speed up access")
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> ---

Did this ever work? Was it tested when you sent the big refactoring
patch set?
Christian Marangi Sept. 5, 2022, 4:59 p.m. UTC | #2
On Mon, Sep 05, 2022 at 07:50:39PM +0300, Vladimir Oltean wrote:
> On Sun, Sep 04, 2022 at 11:53:19PM +0200, Christian Marangi wrote:
> > of_device_get_match_data is called on priv->dev before priv->dev is
> > actually set. Move of_device_get_match_data after priv->dev is correctly
> > set to fix this kernel panic.
> > 
> > Fixes: 3bb0844e7bcd ("net: dsa: qca8k: cache match data to speed up access")
> > Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> > ---
> 
> Did this ever work? Was it tested when you sent the big refactoring
> patch set?

I have to be honest here. I feel really embarrassed about this.
The short story is that the refactor was tested on Openwrt with 5.15 by
manually applying the changes. This fix was applied there but I forgot
to put it in the final series.

I notice this mistake only now that I'm backporting patches and the
manually applied fix was reset.

Again I'm really sorry.
Vladimir Oltean Sept. 5, 2022, 5:10 p.m. UTC | #3
On Sun, Sep 04, 2022 at 11:53:19PM +0200, Christian Marangi wrote:
> of_device_get_match_data is called on priv->dev before priv->dev is
> actually set. Move of_device_get_match_data after priv->dev is correctly
> set to fix this kernel panic.
> 
> Fixes: 3bb0844e7bcd ("net: dsa: qca8k: cache match data to speed up access")
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> ---

Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
patchwork-bot+netdevbpf@kernel.org Sept. 6, 2022, 9:40 a.m. UTC | #4
Hello:

This patch was applied to netdev/net.git (master)
by Paolo Abeni <pabeni@redhat.com>:

On Sun,  4 Sep 2022 23:53:19 +0200 you wrote:
> of_device_get_match_data is called on priv->dev before priv->dev is
> actually set. Move of_device_get_match_data after priv->dev is correctly
> set to fix this kernel panic.
> 
> Fixes: 3bb0844e7bcd ("net: dsa: qca8k: cache match data to speed up access")
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> 
> [...]

Here is the summary with links:
  - [net] net: dsa: qca8k: fix NULL pointer dereference for of_device_get_match_data
    https://git.kernel.org/netdev/net/c/42b998d4aa59

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c
index 1d3e7782a71f..c181346388a4 100644
--- a/drivers/net/dsa/qca/qca8k-8xxx.c
+++ b/drivers/net/dsa/qca/qca8k-8xxx.c
@@ -1889,9 +1889,9 @@  qca8k_sw_probe(struct mdio_device *mdiodev)
 	if (!priv)
 		return -ENOMEM;
 
-	priv->info = of_device_get_match_data(priv->dev);
 	priv->bus = mdiodev->bus;
 	priv->dev = &mdiodev->dev;
+	priv->info = of_device_get_match_data(priv->dev);
 
 	priv->reset_gpio = devm_gpiod_get_optional(priv->dev, "reset",
 						   GPIOD_ASIS);