Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

RDMA/irdma: Fix possible crash due to NULL netdev in notifier

For some net events in irdma_net_event notifier, the netdev can be NULL
which will cause a crash in rdma_vlan_dev_real_dev. Fix this by moving
all processing to the NETEVENT_NEIGH_UPDATE case where the netdev is
guaranteed to not be NULL.

Fixes: 6702bc147448 ("RDMA/irdma: Fix netdev notifications for vlan's")
Link: https://lore.kernel.org/r/20220425181703.1634-4-shiraz.saleem@intel.com
Signed-off-by: Mustafa Ismail <mustafa.ismail@intel.com>
Signed-off-by: Shiraz Saleem <shiraz.saleem@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

authored by

Mustafa Ismail and committed by
Jason Gunthorpe
1c9043ae 2df6d895

+9 -12
+9 -12
drivers/infiniband/hw/irdma/utils.c
··· 258 258 u32 local_ipaddr[4] = {}; 259 259 bool ipv4 = true; 260 260 261 - real_dev = rdma_vlan_dev_real_dev(netdev); 262 - if (!real_dev) 263 - real_dev = netdev; 264 - 265 - ibdev = ib_device_get_by_netdev(real_dev, RDMA_DRIVER_IRDMA); 266 - if (!ibdev) 267 - return NOTIFY_DONE; 268 - 269 - iwdev = to_iwdev(ibdev); 270 - 271 261 switch (event) { 272 262 case NETEVENT_NEIGH_UPDATE: 263 + real_dev = rdma_vlan_dev_real_dev(netdev); 264 + if (!real_dev) 265 + real_dev = netdev; 266 + ibdev = ib_device_get_by_netdev(real_dev, RDMA_DRIVER_IRDMA); 267 + if (!ibdev) 268 + return NOTIFY_DONE; 269 + 270 + iwdev = to_iwdev(ibdev); 273 271 p = (__be32 *)neigh->primary_key; 274 272 if (neigh->tbl->family == AF_INET6) { 275 273 ipv4 = false; ··· 288 290 irdma_manage_arp_cache(iwdev->rf, neigh->ha, 289 291 local_ipaddr, ipv4, 290 292 IRDMA_ARP_DELETE); 293 + ib_device_put(ibdev); 291 294 break; 292 295 default: 293 296 break; 294 297 } 295 - 296 - ib_device_put(ibdev); 297 298 298 299 return NOTIFY_DONE; 299 300 }