netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Johan Hovold <johan@kernel.org>
Cc: Hauke Mehrtens <hauke@hauke-m.de>,
	Vivien Didelot <vivien.didelot@gmail.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable <stable@vger.kernel.org>
Subject: Re: [PATCH 1/3] net: dsa: lantiq_gswip: fix use-after-free on failed probe
Date: Wed, 16 Jan 2019 16:00:09 +0100	[thread overview]
Message-ID: <20190116150009.GE25731@lunn.ch> (raw)
In-Reply-To: <20190116102335.30433-2-johan@kernel.org>

On Wed, Jan 16, 2019 at 11:23:33AM +0100, Johan Hovold wrote:
> Make sure to disable and deregister the switch on late probe errors to
> avoid use-after-free when the device-resource-managed switch is freed.
> 
> Fixes: 14fceff4771e ("net: dsa: Add Lantiq / Intel DSA driver for vrx200")
> Cc: stable <stable@vger.kernel.org>	# 4.20
> Cc: Hauke Mehrtens <hauke@hauke-m.de>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>  drivers/net/dsa/lantiq_gswip.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c
> index 693a67f45bef..b06c41c98de9 100644
> --- a/drivers/net/dsa/lantiq_gswip.c
> +++ b/drivers/net/dsa/lantiq_gswip.c
> @@ -1099,7 +1099,7 @@ static int gswip_probe(struct platform_device *pdev)
>  		dev_err(dev, "wrong CPU port defined, HW only supports port: %i",
>  			priv->hw_info->cpu_port);
>  		err = -EINVAL;
> -		goto mdio_bus;
> +		goto disable_switch;
>  	}
>  
>  	platform_set_drvdata(pdev, priv);
> @@ -1109,6 +1109,9 @@ static int gswip_probe(struct platform_device *pdev)
>  		 (version & GSWIP_VERSION_MOD_MASK) >> GSWIP_VERSION_MOD_SHIFT);
>  	return 0;
>  
> +disable_switch:
> +	gswip_mdio_mask(priv, GSWIP_MDIO_GLOB_ENABLE, 0, GSWIP_MDIO_GLOB);
> +	dsa_unregister_switch(priv->ds);

This is correct. But it would be nice if somebody in the future could
move the disabling of the switch to the inverse of the gswip_setup()
function to make the code symmetrical.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

  reply	other threads:[~2019-01-16 15:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-16 10:23 [PATCH 0/3] net: dsa: lantiq_gswip: probe fixes and remove cleanup Johan Hovold
2019-01-16 10:23 ` [PATCH 1/3] net: dsa: lantiq_gswip: fix use-after-free on failed probe Johan Hovold
2019-01-16 15:00   ` Andrew Lunn [this message]
2019-01-16 21:43     ` Hauke Mehrtens
2019-01-16 22:15       ` Andrew Lunn
2019-01-16 21:42   ` Hauke Mehrtens
2019-01-16 10:23 ` [PATCH 2/3] net: dsa: lantiq_gswip: fix OF child-node lookups Johan Hovold
2019-01-16 15:02   ` Andrew Lunn
2019-01-16 21:46   ` Hauke Mehrtens
2019-01-16 10:23 ` [PATCH 3/3] net: dsa: lantiq_gswip: drop bogus drvdata check Johan Hovold
2019-01-16 15:02   ` Andrew Lunn
2019-01-16 21:46   ` Hauke Mehrtens
2019-01-17 20:12 ` [PATCH 0/3] net: dsa: lantiq_gswip: probe fixes and remove cleanup David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190116150009.GE25731@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=hauke@hauke-m.de \
    --cc=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=vivien.didelot@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).