• Yunsheng Lin's avatar
    net: hns3: fix a use after free problem in hns3_nic_maybe_stop_tx() · d1a37ded
    Yunsheng Lin authored
    Currently, hns3_nic_maybe_stop_tx() uses skb_copy() to linearize a
    SKB if the BD num required by the SKB does not meet the hardware
    limitation, and it linearizes the SKB by allocating a new linearized SKB
    and freeing the old SKB, if hns3_nic_maybe_stop_tx() returns -EBUSY
    because there are no enough space in the ring to send the linearized
    skb to hardware, the sch_direct_xmit() still hold reference to old SKB
    and try to retransmit the old SKB when dev_hard_start_xmit() return
    TX_BUSY, which may cause use after freed problem.
    
    This patch fixes it by using __skb_linearize() to linearize the
    SKB in hns3_nic_maybe_stop_tx().
    
    Fixes: 51e8439f ("net: hns3: add 8 BD limit for tx flow")
    Signed-off-by: default avatarYunsheng Lin <linyunsheng@huawei.com>
    Signed-off-by: default avatarHuazhong Tan <tanhuazhong@huawei.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    d1a37ded
hns3_enet.c 119 KB