Skip to content

Commit ba2f6ec

Browse files
alobakingregkh
authored andcommitted
ice: arfs: fix use-after-free when freeing @rx_cpu_rmap
commit d7442f512b71fc63a99c8a801422dde4fbbf9f93 upstream. The CI testing bots triggered the following splat: [ 718.203054] BUG: KASAN: use-after-free in free_irq_cpu_rmap+0x53/0x80 [ 718.206349] Read of size 4 at addr ffff8881bd127e00 by task sh/20834 [ 718.212852] CPU: 28 PID: 20834 Comm: sh Kdump: loaded Tainted: G S W IOE 5.17.0-rc8_nextqueue-devqueue-02643-g23f3121aca93 #1 [ 718.219695] Hardware name: Intel Corporation S2600WFT/S2600WFT, BIOS SE5C620.86B.02.01.0012.070720200218 07/07/2020 [ 718.223418] Call Trace: [ 718.227139] [ 718.230783] dump_stack_lvl+0x33/0x42 [ 718.234431] print_address_description.constprop.9+0x21/0x170 [ 718.238177] ? free_irq_cpu_rmap+0x53/0x80 [ 718.241885] ? free_irq_cpu_rmap+0x53/0x80 [ 718.245539] kasan_report.cold.18+0x7f/0x11b [ 718.249197] ? free_irq_cpu_rmap+0x53/0x80 [ 718.252852] free_irq_cpu_rmap+0x53/0x80 [ 718.256471] ice_free_cpu_rx_rmap.part.11+0x37/0x50 [ice] [ 718.260174] ice_remove_arfs+0x5f/0x70 [ice] [ 718.263810] ice_rebuild_arfs+0x3b/0x70 [ice] [ 718.267419] ice_rebuild+0x39c/0xb60 [ice] [ 718.270974] ? asm_sysvec_apic_timer_interrupt+0x12/0x20 [ 718.274472] ? ice_init_phy_user_cfg+0x360/0x360 [ice] [ 718.278033] ? delay_tsc+0x4a/0xb0 [ 718.281513] ? preempt_count_sub+0x14/0xc0 [ 718.284984] ? delay_tsc+0x8f/0xb0 [ 718.288463] ice_do_reset+0x92/0xf0 [ice] [ 718.292014] ice_pci_err_resume+0x91/0xf0 [ice] [ 718.295561] pci_reset_function+0x53/0x80 <...> [ 718.393035] Allocated by task 690: [ 718.433497] Freed by task 20834: [ 718.495688] Last potentially related work creation: [ 718.568966] The buggy address belongs to the object at ffff8881bd127e00 which belongs to the cache kmalloc-96 of size 96 [ 718.574085] The buggy address is located 0 bytes inside of 96-byte region [ffff8881bd127e00, ffff8881bd127e60) [ 718.579265] The buggy address belongs to the page: [ 718.598905] Memory state around the buggy address: [ 718.601809] ffff8881bd127d00: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc [ 718.604796] ffff8881bd127d80: 00 00 00 00 00 00 00 00 00 00 fc fc fc fc fc fc [ 718.607794] >ffff8881bd127e00: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc [ 718.610811] ^ [ 718.613819] ffff8881bd127e80: 00 00 00 00 00 00 00 00 00 00 00 00 fc fc fc fc [ 718.617107] ffff8881bd127f00: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc This is due to that free_irq_cpu_rmap() is always being called *after* (devm_)free_irq() and thus it tries to work with IRQ descs already freed. For example, on device reset the driver frees the rmap right before allocating a new one (the splat above). Make rmap creation and freeing function symmetrical with {request,free}_irq() calls i.e. do that on ifup/ifdown instead of device probe/remove/resume. These operations can be performed independently from the actual device aRFS configuration. Also, make sure ice_vsi_free_irq() clears IRQ affinity notifiers only when aRFS is disabled -- otherwise, CPU rmap sets and clears its own and they must not be touched manually. Fixes: 28bf267 ("ice: Implement aRFS") Co-developed-by: Ivan Vecera <[email protected]> Signed-off-by: Ivan Vecera <[email protected]> Signed-off-by: Alexander Lobakin <[email protected]> Tested-by: Ivan Vecera <[email protected]> Signed-off-by: Tony Nguyen <[email protected]> Signed-off-by: Suraj Jitindar Singh <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2991dc3 commit ba2f6ec

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

drivers/net/ethernet/intel/ice/ice_arfs.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ void ice_free_cpu_rx_rmap(struct ice_vsi *vsi)
577577
{
578578
struct net_device *netdev;
579579

580-
if (!vsi || vsi->type != ICE_VSI_PF || !vsi->arfs_fltr_list)
580+
if (!vsi || vsi->type != ICE_VSI_PF)
581581
return;
582582

583583
netdev = vsi->netdev;
@@ -600,7 +600,7 @@ int ice_set_cpu_rx_rmap(struct ice_vsi *vsi)
600600
int base_idx, i;
601601

602602
if (!vsi || vsi->type != ICE_VSI_PF)
603-
return -EINVAL;
603+
return 0;
604604

605605
pf = vsi->back;
606606
netdev = vsi->netdev;
@@ -638,7 +638,6 @@ void ice_remove_arfs(struct ice_pf *pf)
638638
if (!pf_vsi)
639639
return;
640640

641-
ice_free_cpu_rx_rmap(pf_vsi);
642641
ice_clear_arfs(pf_vsi);
643642
}
644643

@@ -655,9 +654,5 @@ void ice_rebuild_arfs(struct ice_pf *pf)
655654
return;
656655

657656
ice_remove_arfs(pf);
658-
if (ice_set_cpu_rx_rmap(pf_vsi)) {
659-
dev_err(ice_pf_to_dev(pf), "Failed to rebuild aRFS\n");
660-
return;
661-
}
662657
ice_init_arfs(pf_vsi);
663658
}

drivers/net/ethernet/intel/ice/ice_lib.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2411,6 +2411,8 @@ void ice_vsi_free_irq(struct ice_vsi *vsi)
24112411
return;
24122412

24132413
vsi->irqs_ready = false;
2414+
ice_free_cpu_rx_rmap(vsi);
2415+
24142416
ice_for_each_q_vector(vsi, i) {
24152417
u16 vector = i + base;
24162418
int irq_num;
@@ -2424,7 +2426,8 @@ void ice_vsi_free_irq(struct ice_vsi *vsi)
24242426
continue;
24252427

24262428
/* clear the affinity notifier in the IRQ descriptor */
2427-
irq_set_affinity_notifier(irq_num, NULL);
2429+
if (!IS_ENABLED(CONFIG_RFS_ACCEL))
2430+
irq_set_affinity_notifier(irq_num, NULL);
24282431

24292432
/* clear the affinity_mask in the IRQ descriptor */
24302433
irq_set_affinity_hint(irq_num, NULL);

drivers/net/ethernet/intel/ice/ice_main.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,6 +2247,13 @@ static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename)
22472247
irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
22482248
}
22492249

2250+
err = ice_set_cpu_rx_rmap(vsi);
2251+
if (err) {
2252+
netdev_err(vsi->netdev, "Failed to setup CPU RMAP on VSI %u: %pe\n",
2253+
vsi->vsi_num, ERR_PTR(err));
2254+
goto free_q_irqs;
2255+
}
2256+
22502257
vsi->irqs_ready = true;
22512258
return 0;
22522259

@@ -3242,22 +3249,12 @@ static int ice_setup_pf_sw(struct ice_pf *pf)
32423249
*/
32433250
ice_napi_add(vsi);
32443251

3245-
status = ice_set_cpu_rx_rmap(vsi);
3246-
if (status) {
3247-
dev_err(ice_pf_to_dev(pf), "Failed to set CPU Rx map VSI %d error %d\n",
3248-
vsi->vsi_num, status);
3249-
status = -EINVAL;
3250-
goto unroll_napi_add;
3251-
}
32523252
status = ice_init_mac_fltr(pf);
32533253
if (status)
3254-
goto free_cpu_rx_map;
3254+
goto unroll_napi_add;
32553255

32563256
return status;
32573257

3258-
free_cpu_rx_map:
3259-
ice_free_cpu_rx_rmap(vsi);
3260-
32613258
unroll_napi_add:
32623259
if (vsi) {
32633260
ice_napi_del(vsi);
@@ -4598,7 +4595,6 @@ static int __maybe_unused ice_suspend(struct device *dev)
45984595
continue;
45994596
ice_vsi_free_q_vectors(pf->vsi[v]);
46004597
}
4601-
ice_free_cpu_rx_rmap(ice_get_main_vsi(pf));
46024598
ice_clear_interrupt_scheme(pf);
46034599

46044600
pci_save_state(pdev);

0 commit comments

Comments
 (0)