idpf_mac_filter_async_handler() looks up the vport with idpf_vid_to_vport(), but then indexes adapter->vport_config[] with the raw vport_id from the message instead of using the vport it just found. vport_id is a device-assigned 32-bit number and is not limited to num_max_vports, so vport_config[vport_id] can read past the end of the array. Use vport->idx, the array index the rest of the driver uses. During driver removal the vports are freed before the mailbox work is cancelled, so this handler can still run while a vport it looks up is being freed. Return early if IDPF_REMOVE_IN_PROG is set. The filter removal loop in the same handler also leaks: it does list_del() without kfree(), and if the response lists the same MAC more than once it deletes the same entry twice. Free the filter and break out of the inner loop once it is removed. Fixes: 41252855df77 ("idpf: add async_handler for MAC filter messages") Cc: stable@vger.kernel.org Signed-off-by: Hongyu Guo --- drivers/net/ethernet/intel/idpf/idpf_virtchnl.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c index 1caf52706973..ff43a3d34eac 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c @@ -3779,6 +3779,10 @@ static void idpf_mac_filter_async_handler(void *ctx, if (!status || status == -ETIMEDOUT) return; + /* vports are freed during removal, before this work is cancelled */ + if (test_bit(IDPF_REMOVE_IN_PROG, adapter->flags)) + return; + ma_list = buff->iov_base; /* make sure at least struct is there */ if (buff->iov_len < sizeof(*ma_list)) @@ -3794,7 +3798,7 @@ static void idpf_mac_filter_async_handler(void *ctx, if (!vport) goto invalid_payload; - vport_config = adapter->vport_config[le32_to_cpu(ma_list->vport_id)]; + vport_config = adapter->vport_config[vport->idx]; ma_list_head = &vport_config->user_config.mac_filter_list; /* We can't do much to reconcile bad filters at this point, however we @@ -3804,8 +3808,11 @@ static void idpf_mac_filter_async_handler(void *ctx, spin_lock_bh(&vport_config->mac_filter_list_lock); list_for_each_entry_safe(f, tmp, ma_list_head, list) for (i = 0; i < num_entries; i++) - if (ether_addr_equal(mac_addr[i].addr, f->macaddr)) + if (ether_addr_equal(mac_addr[i].addr, f->macaddr)) { list_del(&f->list); + kfree(f); + break; + } spin_unlock_bh(&vport_config->mac_filter_list_lock); dev_err_ratelimited(&adapter->pdev->dev, "Received error %d on sending MAC filter request\n", status); -- 2.43.0