net: hisilicon: Fix potential use-after-free in hix5hd2_rx()
authorLiu Jian <liujian56@huawei.com>
Sat, 3 Dec 2022 09:42:40 +0000 (17:42 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 14 Dec 2022 10:24:34 +0000 (11:24 +0100)
[ Upstream commit 433c07a13f59856e4585e89e86b7d4cc59348fab ]

The skb is delivered to napi_gro_receive() which may free it, after
calling this, dereferencing skb may trigger use-after-free.

Fixes: 57c5bc9ad7d7 ("net: hisilicon: add hix5hd2 mac driver")
Signed-off-by: Liu Jian <liujian56@huawei.com>
Link: https://lore.kernel.org/r/20221203094240.1240211-2-liujian56@huawei.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c

index dd24c352b200083ca356eb831b865507ab357e57..4dc6c3e99d15dce88596e357ae209e2889f64fef 100644 (file)
@@ -498,7 +498,7 @@ static int hix5hd2_rx(struct net_device *dev, int limit)
                skb->protocol = eth_type_trans(skb, dev);
                napi_gro_receive(&priv->napi, skb);
                dev->stats.rx_packets++;
-               dev->stats.rx_bytes += skb->len;
+               dev->stats.rx_bytes += len;
 next:
                pos = dma_ring_incr(pos, RX_DESC_NUM);
        }