net: microchip: sparx5: Fix potential null-ptr-deref in sparx_stats_init() and sparx5...
authorShang XiaoJing <shangxiaojing@huawei.com>
Mon, 14 Nov 2022 13:38:53 +0000 (21:38 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 26 Nov 2022 08:24:41 +0000 (09:24 +0100)
commit80e590aeb132887102c3fa79d99b338f099dc952
treeda3fd13ff9fccc4eb3cd0c3c15621135b3b57f56
parent4a55aec1425fc8e9bd5ea7c2f837e8ea2f380ae1
net: microchip: sparx5: Fix potential null-ptr-deref in sparx_stats_init() and sparx5_start()

[ Upstream commit 639f5d006e36bb303f525d9479448c412b720c39 ]

sparx_stats_init() calls create_singlethread_workqueue() and not
checked the ret value, which may return NULL. And a null-ptr-deref may
happen:

sparx_stats_init()
    create_singlethread_workqueue() # failed, sparx5->stats_queue is NULL
    queue_delayed_work()
        queue_delayed_work_on()
            __queue_delayed_work()  # warning here, but continue
                __queue_work()      # access wq->flags, null-ptr-deref

Check the ret value and return -ENOMEM if it is NULL. So as
sparx5_start().

Fixes: af4b11022e2d ("net: sparx5: add ethtool configuration and statistics support")
Fixes: b37a1bae742f ("net: sparx5: add mactable support")
Signed-off-by: Shang XiaoJing <shangxiaojing@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c
drivers/net/ethernet/microchip/sparx5/sparx5_main.c