提交 7b9501c2 编写于 作者: L Lin Ma 提交者: Yongqiang Liu

hamradio: defer ax25 kfree after unregister_netdev

stable inclusion
from stable-v4.19.223
commit 896193a02a2981e60c40d4614fd095ce92135ccd
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I55483
CVE: CVE-2022-1195

-------------------------------------------------

commit 3e0588c2 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: NLin Ma <linma@zju.edu.cn>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NHuang Guobin <huangguobin4@huawei.com>
Reviewed-by: NWei Yongjun <weiyongjun1@huawei.com>
Reviewed-by: NXiu Jianfeng <xiujianfeng@huawei.com>
Signed-off-by: NYongqiang Liu <liuyongqiang13@huawei.com>
上级 7883a93a
...@@ -803,13 +803,13 @@ static void mkiss_close(struct tty_struct *tty) ...@@ -803,13 +803,13 @@ static void mkiss_close(struct tty_struct *tty)
*/ */
netif_stop_queue(ax->dev); netif_stop_queue(ax->dev);
/* Free all AX25 frame buffers. */
kfree(ax->rbuff);
kfree(ax->xbuff);
ax->tty = NULL; ax->tty = NULL;
unregister_netdev(ax->dev); unregister_netdev(ax->dev);
/* Free all AX25 frame buffers. */
kfree(ax->rbuff);
kfree(ax->xbuff);
} }
/* Perform I/O control on an active ax25 channel. */ /* Perform I/O control on an active ax25 channel. */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册