[PATCH v1] hamradio: remove needs_free_netdev to avoid UAF

Subsystems: networking drivers, the rest

STALE1772d LANDED

Landed in mainline as 81b1d548d00b on 2021-11-13.

3 messages, 3 authors, 2021-11-13 · open the first message on its own page

[PATCH v1] hamradio: remove needs_free_netdev to avoid UAF

From: Lin Ma <hidden>
Date: 2021-11-11 14:14:14

The former patch "defer 6pack kfree after unregister_netdev" reorders
the kfree of two buffer after the unregister_netdev to prevent the race
condition. It also adds free_netdev() function in sixpack_close(), which
is a direct copy from the similar code in mkiss_close().

However, in sixpack driver, the flag needs_free_netdev is set to true in
sp_setup(), hence the unregister_netdev() will free the netdev
automatically. Therefore, as the sp is netdev_priv, use-after-free
occurs.

This patch removes the needs_free_netdev = true and just let the
free_netdev to finish this deallocation task.

Signed-off-by: Lin Ma <redacted>
---
 drivers/net/hamradio/6pack.c | 1 -
 1 file changed, 1 deletion(-)
diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
index bfdf89e54752..8a19a06b505d 100644
--- a/drivers/net/hamradio/6pack.c
+++ b/drivers/net/hamradio/6pack.c
@@ -306,7 +306,6 @@ static void sp_setup(struct net_device *dev)
 {
 	/* Finish setting up the DEVICE info. */
 	dev->netdev_ops		= &sp_netdev_ops;
-	dev->needs_free_netdev	= true;
 	dev->mtu		= SIXP_MTU;
 	dev->hard_header_len	= AX25_MAX_HEADER_LEN;
 	dev->header_ops 	= &ax25_header_ops;
-- 
2.33.1

Re: [PATCH v1] hamradio: remove needs_free_netdev to avoid UAF

From: Jakub Kicinski <kuba@kernel.org>
Date: 2021-11-12 01:55:05

On Thu, 11 Nov 2021 22:14:02 +0800 Lin Ma wrote:
The former patch "defer 6pack kfree after unregister_netdev" reorders
the kfree of two buffer after the unregister_netdev to prevent the race
condition. It also adds free_netdev() function in sixpack_close(), which
is a direct copy from the similar code in mkiss_close().

However, in sixpack driver, the flag needs_free_netdev is set to true in
sp_setup(), hence the unregister_netdev() will free the netdev
automatically. Therefore, as the sp is netdev_priv, use-after-free
occurs.

This patch removes the needs_free_netdev = true and just let the
free_netdev to finish this deallocation task.

Signed-off-by: Lin Ma <redacted>
Fixes: 0b9111922b1f ("hamradio: defer 6pack kfree after unregister_netdev")

Re: [PATCH v1] hamradio: remove needs_free_netdev to avoid UAF

From: patchwork-bot+netdevbpf@kernel.org
Date: 2021-11-13 04:20:27

Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski [off-list ref]:

On Thu, 11 Nov 2021 22:14:02 +0800 you wrote:
The former patch "defer 6pack kfree after unregister_netdev" reorders
the kfree of two buffer after the unregister_netdev to prevent the race
condition. It also adds free_netdev() function in sixpack_close(), which
is a direct copy from the similar code in mkiss_close().

However, in sixpack driver, the flag needs_free_netdev is set to true in
sp_setup(), hence the unregister_netdev() will free the netdev
automatically. Therefore, as the sp is netdev_priv, use-after-free
occurs.

[...]
Here is the summary with links:
  - [v1] hamradio: remove needs_free_netdev to avoid UAF
    https://git.kernel.org/netdev/net/c/81b1d548d00b

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help