* [PATCH] net/ethoc: fix null dereference on error exit path
@ 2016-05-22 19:08 Colin King
2016-05-22 19:42 ` Max Filippov
0 siblings, 1 reply; 3+ messages in thread
From: Colin King @ 2016-05-22 19:08 UTC (permalink / raw)
To: David S . Miller, Andrew Lunn, Florian Fainelli, Tobias Klauser,
Max Filippov, netdev
Cc: linux-kernel
From: Colin Ian King <colin.king@canonical.com>
priv is assigned to NULL however all the error exit paths to label 'free'
dereference priv, causing a null pointer dereference.
Examination of the code shows that all error exits via the 'free'
label path occur before priv is assigned to netdev_priv(netdev), hence
there is no need to call clk_disable_unprepare and so the location of
the label should be moved to free_netdev statement to avoid this null
dereference on priv.
Fixes issue found by CoverityScan, CID#113260
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/net/ethernet/ethoc.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/ethoc.c b/drivers/net/ethernet/ethoc.c
index 41b0106..96403a4 100644
--- a/drivers/net/ethernet/ethoc.c
+++ b/drivers/net/ethernet/ethoc.c
@@ -1241,9 +1241,10 @@ error2:
error:
mdiobus_unregister(priv->mdio);
mdiobus_free(priv->mdio);
-free:
+
if (priv->clk)
clk_disable_unprepare(priv->clk);
+free:
free_netdev(netdev);
out:
return ret;
--
2.8.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net/ethoc: fix null dereference on error exit path
2016-05-22 19:08 [PATCH] net/ethoc: fix null dereference on error exit path Colin King
@ 2016-05-22 19:42 ` Max Filippov
2016-05-22 21:20 ` Colin Ian King
0 siblings, 1 reply; 3+ messages in thread
From: Max Filippov @ 2016-05-22 19:42 UTC (permalink / raw)
To: Colin King
Cc: David S . Miller, Andrew Lunn, Florian Fainelli, Tobias Klauser,
netdev, linux-kernel
Hi Colin,
On Sun, May 22, 2016 at 08:08:18PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> priv is assigned to NULL however all the error exit paths to label 'free'
> dereference priv, causing a null pointer dereference.
>
> Examination of the code shows that all error exits via the 'free'
> label path occur before priv is assigned to netdev_priv(netdev), hence
> there is no need to call clk_disable_unprepare and so the location of
> the label should be moved to free_netdev statement to avoid this null
> dereference on priv.
This description is a bit inaccurate. Indeed all 'goto free' above the
'priv = netdev_priv(netdev);' need to skip 'if (priv->clk)' check, but
there are two more 'goto free' below that line, and they look correct
now, but after this patch they'll leave the clock enabled.
--
Thanks.
-- Max
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net/ethoc: fix null dereference on error exit path
2016-05-22 19:42 ` Max Filippov
@ 2016-05-22 21:20 ` Colin Ian King
0 siblings, 0 replies; 3+ messages in thread
From: Colin Ian King @ 2016-05-22 21:20 UTC (permalink / raw)
To: Max Filippov
Cc: David S . Miller, Andrew Lunn, Florian Fainelli, Tobias Klauser,
netdev, linux-kernel
On 22/05/16 20:42, Max Filippov wrote:
> Hi Colin,
>
> On Sun, May 22, 2016 at 08:08:18PM +0100, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> priv is assigned to NULL however all the error exit paths to label 'free'
>> dereference priv, causing a null pointer dereference.
>>
>> Examination of the code shows that all error exits via the 'free'
>> label path occur before priv is assigned to netdev_priv(netdev), hence
>> there is no need to call clk_disable_unprepare and so the location of
>> the label should be moved to free_netdev statement to avoid this null
>> dereference on priv.
>
> This description is a bit inaccurate. Indeed all 'goto free' above the
> 'priv = netdev_priv(netdev);' need to skip 'if (priv->clk)' check, but
> there are two more 'goto free' below that line, and they look correct
> now, but after this patch they'll leave the clock enabled.
>
Oops, I'll resend a corrected fix tomorrow
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-05-22 21:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-22 19:08 [PATCH] net/ethoc: fix null dereference on error exit path Colin King
2016-05-22 19:42 ` Max Filippov
2016-05-22 21:20 ` Colin Ian King
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).