From 8520fb399fb6c143f65cf9b7e908ef57f8731683 Mon Sep 17 00:00:00 2001 From: xuwenhan Date: Mon, 9 Oct 2023 22:47:17 +0800 Subject: [PATCH] Add a check of netdev in veth_netdev_init() driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I86N2E ------------------------------------------------- In veth_netdev_init(), netdev is allocated using alloc_netdev_mq(), which can fail and return NULL. Then function register_netdev(netdev) => register_netdevice(dev) => dev_net(dev) is executed in sequence, and &dev->nd_net is accessed, which causes a null-pointer dereference. To fix this possible bug, netdev should be checked after the call to alloc_netdev_mq(). Signed-off-by: xuwenhan --- drivers/net/ethernet/huawei/bma/veth_drv/veth_hb.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/ethernet/huawei/bma/veth_drv/veth_hb.c b/drivers/net/ethernet/huawei/bma/veth_drv/veth_hb.c index 6a7175c6206c..556b229b77b6 100644 --- a/drivers/net/ethernet/huawei/bma/veth_drv/veth_hb.c +++ b/drivers/net/ethernet/huawei/bma/veth_drv/veth_hb.c @@ -1645,6 +1645,9 @@ s32 veth_netdev_init(void) BSPVETH_DEV_NAME, NET_NAME_UNKNOWN, veth_netdev_func_init, 1); + if (!netdev) + return -ENOMEM; + /* register netdev */ l_ret = register_netdev(netdev); if (l_ret < 0) { -- Gitee