OSDN Git Service

net: rocker: fix a potential NULL pointer dereference
authorKangjie Lu <kjlu@umn.edu>
Mon, 11 Mar 2019 07:06:06 +0000 (02:06 -0500)
committerDavid S. Miller <davem@davemloft.net>
Mon, 11 Mar 2019 23:17:31 +0000 (16:17 -0700)
In case kzalloc fails, the fix releases resources and returns
NOTIFY_BAD to avoid NULL pointer dereference.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/rocker/rocker_main.c

index c883aa8..a71c900 100644 (file)
@@ -2805,6 +2805,11 @@ static int rocker_switchdev_event(struct notifier_block *unused,
                memcpy(&switchdev_work->fdb_info, ptr,
                       sizeof(switchdev_work->fdb_info));
                switchdev_work->fdb_info.addr = kzalloc(ETH_ALEN, GFP_ATOMIC);
+               if (unlikely(!switchdev_work->fdb_info.addr)) {
+                       kfree(switchdev_work);
+                       return NOTIFY_BAD;
+               }
+
                ether_addr_copy((u8 *)switchdev_work->fdb_info.addr,
                                fdb_info->addr);
                /* Take a reference on the rocker device */