diff mbox series

[v1] hamradio: remove needs_free_netdev to avoid UAF

Message ID 20211111141402.7551-1-linma@zju.edu.cn (mailing list archive)
State Accepted
Commit 81b1d548d00bcd028303c4f3150fa753b9b8aa71
Delegated to: Netdev Maintainers
Headers show
Series [v1] hamradio: remove needs_free_netdev to avoid UAF | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
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 warning 2 maintainers not CCed: linux-hams@vger.kernel.org ajk@comnets.uni-bremen.de
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/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Lin Ma Nov. 11, 2021, 2:14 p.m. UTC
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 <linma@zju.edu.cn>
---
 drivers/net/hamradio/6pack.c | 1 -
 1 file changed, 1 deletion(-)

Comments

Jakub Kicinski Nov. 12, 2021, 1:55 a.m. UTC | #1
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 <linma@zju.edu.cn>

Fixes: 0b9111922b1f ("hamradio: defer 6pack kfree after unregister_netdev")
patchwork-bot+netdevbpf@kernel.org Nov. 13, 2021, 4:20 a.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:

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!
diff mbox series

Patch

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;