Skip to content

Commit 1eb0db7

Browse files
jahay1anguy11
authored andcommitted
idpf: clear stale cdev_info ptr
Deinit calls idpf_idc_deinit_core_aux_device to free the cdev_info memory, but leaves the adapter->cdev_info field with a stale pointer value. This will bypass subsequent "if (!cdev_info)" checks if cdev_info is not reallocated. For example, if idc_init fails after a reset, cdev_info will already have been freed during the reset handling, but it will not have been reallocated. The next reset or rmmod will result in a crash. [ +0.000008] BUG: kernel NULL pointer dereference, address: 00000000000000d0 [ +0.000033] #PF: supervisor read access in kernel mode [ +0.000020] #PF: error_code(0x0000) - not-present page [ +0.000017] PGD 2097dfa067 P4D 0 [ +0.000017] Oops: Oops: 0000 [#1] SMP NOPTI ... [ +0.000018] RIP: 0010:device_del+0x3e/0x3d0 [ +0.000010] Call Trace: [ +0.000010] <TASK> [ +0.000012] idpf_idc_deinit_core_aux_device+0x36/0x70 [idpf] [ +0.000034] idpf_vc_core_deinit+0x3e/0x180 [idpf] [ +0.000035] idpf_remove+0x40/0x1d0 [idpf] [ +0.000035] pci_device_remove+0x42/0xb0 [ +0.000020] device_release_driver_internal+0x19c/0x200 [ +0.000024] driver_detach+0x48/0x90 [ +0.000018] bus_remove_driver+0x6d/0x100 [ +0.000023] pci_unregister_driver+0x2e/0xb0 [ +0.000022] __do_sys_delete_module.isra.0+0x18c/0x2b0 [ +0.000025] ? kmem_cache_free+0x2c2/0x390 [ +0.000023] do_syscall_64+0x107/0x7d0 [ +0.000023] entry_SYSCALL_64_after_hwframe+0x76/0x7e Pass the adapter struct into idpf_idc_deinit_core_aux_device instead and clear the cdev_info ptr. Fixes: f4312e6 ("idpf: implement core RDMA auxiliary dev create, init, and destroy") Signed-off-by: Joshua Hay <[email protected]> Reviewed-by: Przemek Kitszel <[email protected]> Reviewed-by: Aleksandr Loktionov <[email protected]> Reviewed-by: Simon Horman <[email protected]> Tested-by: Samuel Salin <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent fecacfc commit 1eb0db7

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

drivers/net/ethernet/intel/idpf/idpf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ bool idpf_vport_set_hsplit(const struct idpf_vport *vport, u8 val);
10661066
int idpf_idc_init(struct idpf_adapter *adapter);
10671067
int idpf_idc_init_aux_core_dev(struct idpf_adapter *adapter,
10681068
enum iidc_function_type ftype);
1069-
void idpf_idc_deinit_core_aux_device(struct iidc_rdma_core_dev_info *cdev_info);
1069+
void idpf_idc_deinit_core_aux_device(struct idpf_adapter *adapter);
10701070
void idpf_idc_deinit_vport_aux_device(struct iidc_rdma_vport_dev_info *vdev_info);
10711071
void idpf_idc_issue_reset_event(struct iidc_rdma_core_dev_info *cdev_info);
10721072
void idpf_idc_vdev_mtu_event(struct iidc_rdma_vport_dev_info *vdev_info,

drivers/net/ethernet/intel/idpf/idpf_idc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,11 @@ int idpf_idc_init_aux_core_dev(struct idpf_adapter *adapter,
470470

471471
/**
472472
* idpf_idc_deinit_core_aux_device - de-initialize Auxiliary Device(s)
473-
* @cdev_info: IDC core device info pointer
473+
* @adapter: driver private data structure
474474
*/
475-
void idpf_idc_deinit_core_aux_device(struct iidc_rdma_core_dev_info *cdev_info)
475+
void idpf_idc_deinit_core_aux_device(struct idpf_adapter *adapter)
476476
{
477+
struct iidc_rdma_core_dev_info *cdev_info = adapter->cdev_info;
477478
struct iidc_rdma_priv_dev_info *privd;
478479

479480
if (!cdev_info)
@@ -485,6 +486,7 @@ void idpf_idc_deinit_core_aux_device(struct iidc_rdma_core_dev_info *cdev_info)
485486
kfree(privd->mapped_mem_regions);
486487
kfree(privd);
487488
kfree(cdev_info);
489+
adapter->cdev_info = NULL;
488490
}
489491

490492
/**

drivers/net/ethernet/intel/idpf/idpf_virtchnl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3668,7 +3668,7 @@ void idpf_vc_core_deinit(struct idpf_adapter *adapter)
36683668

36693669
idpf_ptp_release(adapter);
36703670
idpf_deinit_task(adapter);
3671-
idpf_idc_deinit_core_aux_device(adapter->cdev_info);
3671+
idpf_idc_deinit_core_aux_device(adapter);
36723672
idpf_rel_rx_pt_lkup(adapter);
36733673
idpf_intr_rel(adapter);
36743674

0 commit comments

Comments
 (0)