Skip to content

Commit cb6c99a

Browse files
f0rm2l1ngregkh
authored andcommitted
hamradio: defer ax25 kfree after unregister_netdev
commit 3e0588c upstream. There is a possible race condition (use-after-free) like below (USE) | (FREE) ax25_sendmsg | ax25_queue_xmit | dev_queue_xmit | __dev_queue_xmit | __dev_xmit_skb | sch_direct_xmit | ... xmit_one | netdev_start_xmit | tty_ldisc_kill __netdev_start_xmit | mkiss_close ax_xmit | kfree ax_encaps | | Even though there are two synchronization primitives before the kfree: 1. wait_for_completion(&ax->dead). This can prevent the race with routines from mkiss_ioctl. However, it cannot stop the routine coming from upper layer, i.e., the ax25_sendmsg. 2. netif_stop_queue(ax->dev). It seems that this line of code aims to halt the transmit queue but it fails to stop the routine that already being xmit. This patch reorder the kfree after the unregister_netdev to avoid the possible UAF as the unregister_netdev() is well synchronized and won't return if there is a running routine. Signed-off-by: Lin Ma <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a8e4a64 commit cb6c99a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/net/hamradio/mkiss.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,13 +792,14 @@ static void mkiss_close(struct tty_struct *tty)
792792
*/
793793
netif_stop_queue(ax->dev);
794794

795-
/* Free all AX25 frame buffers. */
796-
kfree(ax->rbuff);
797-
kfree(ax->xbuff);
798-
799795
ax->tty = NULL;
800796

801797
unregister_netdev(ax->dev);
798+
799+
/* Free all AX25 frame buffers after unreg. */
800+
kfree(ax->rbuff);
801+
kfree(ax->xbuff);
802+
802803
free_netdev(ax->dev);
803804
}
804805

0 commit comments

Comments
 (0)