From: Wen Yang Date: Sat, 6 Jul 2019 03:37:20 +0000 (+0800) Subject: can: flexcan: fix an use-after-free in flexcan_setup_stop_mode() X-Git-Tag: v5.2.9~98 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=a4b88383cc79564853360c2cd6ba87420d2f3e3a;p=users%2Fdwmw2%2Flinux.git can: flexcan: fix an use-after-free in flexcan_setup_stop_mode() commit e9f2a856e102fa27715b94bcc2240f686536d29b upstream. The gpr_np variable is still being used in dev_dbg() after the of_node_put() call, which may result in use-after-free. Fixes: de3578c198c6 ("can: flexcan: add self wakeup support") Signed-off-by: Wen Yang Cc: linux-stable # >= v5.0 Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c index 6b55398b47292..fcec8bcb53d64 100644 --- a/drivers/net/can/flexcan.c +++ b/drivers/net/can/flexcan.c @@ -1455,10 +1455,10 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev) priv = netdev_priv(dev); priv->stm.gpr = syscon_node_to_regmap(gpr_np); - of_node_put(gpr_np); if (IS_ERR(priv->stm.gpr)) { dev_dbg(&pdev->dev, "could not find gpr regmap\n"); - return PTR_ERR(priv->stm.gpr); + ret = PTR_ERR(priv->stm.gpr); + goto out_put_node; } priv->stm.req_gpr = out_val[1]; @@ -1473,7 +1473,9 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev) device_set_wakeup_capable(&pdev->dev, true); - return 0; +out_put_node: + of_node_put(gpr_np); + return ret; } static const struct of_device_id flexcan_of_match[] = {