Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jacob Keller <jacob.e.keller@intel.com>
To: <intel-wired-lan@osuosl.org>
Subject: Re: [Intel-wired-lan] [net-next, v2 2/2] ice: Accumulate ring statistics over reset
Date: Fri, 14 Oct 2022 15:33:05 -0700	[thread overview]
Message-ID: <228a8e08-5aec-43b9-6f4b-c8636420e228@intel.com> (raw)
In-Reply-To: <20221010192223.916578-3-benjamin.mikailenko@intel.com>



On 10/10/2022 12:22 PM, Benjamin Mikailenko wrote:
> Resets may occur with or without user interaction. For example, a TX hang
> or reconfiguration of parameters will result in a reset. During reset, the
> VSI is freed, freeing any statistics structures inside as well. This would
> create an issue for the user where a reset happens in the background,
> statistics set to zero, and the user checks ring statistics expecting them
> to be populated.
> 
> To ensure this doesn't happen, accumulate ring statistics over reset.
> 
> Define a new ring statistics structure, ice_ring_stats. The new structure
> lives in the VSI's parent, preserving ring statistics when VSI is freed.
> 
> 1. Define a new structure vsi_ring_stats in the PF scope
> 2. Allocate/free stats only during probe, unload, or change in ring size
> 3. Replace previous ring statistics functionality with new structure
> 
> Signed-off-by: Benjamin Mikailenko <benjamin.mikailenko@intel.com>
> ---

I found a potential use-after-free bug in ice_vsi_alloc with these changes:

>  /**
>   * ice_vsi_alloc - Allocates the next available struct VSI in the PF
>   * @pf: board private structure
> @@ -560,6 +606,11 @@ ice_vsi_alloc(struct ice_pf *pf, enum ice_vsi_type vsi_type,
>  
>  	if (vsi->type == ICE_VSI_CTRL && vf)
>  		vf->ctrl_vsi_idx = vsi->idx;
> +
> +	/* allocate memory for Tx/Rx ring stat pointers */
> +	if (ice_vsi_alloc_stat_arrays(vsi))
> +		goto err_rings;
> +
>  	goto unlock_pf;
>  

This is placed in ice_vsi_alloc after we insert the VSI into the PF
array and update pointers such as the next_vsi and ctrl_vsi_idx. Doing
so means that if this function fails we will leave stale data behind in
the PF resulting in a use-after-free when tearing down all the VSIs.

This can be avoided by moving this logic up higher to just before we
update the PF VSI array.

Thanks,
Jake
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

  parent reply	other threads:[~2022-10-14 22:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-10 19:22 [Intel-wired-lan] [net-next, v2 0/2] ice: Accumulate statistics over reset Benjamin Mikailenko
2022-10-10 19:22 ` [Intel-wired-lan] [net-next, v2 1/2] ice: Accumulate HW and Netdev " Benjamin Mikailenko
2022-10-12 13:37   ` G, GurucharanX
2022-10-10 19:22 ` [Intel-wired-lan] [net-next, v2 2/2] ice: Accumulate ring " Benjamin Mikailenko
2022-10-12 13:38   ` G, GurucharanX
2022-10-14 22:33   ` Jacob Keller [this message]
2022-10-14 22:44   ` Jacob Keller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=228a8e08-5aec-43b9-6f4b-c8636420e228@intel.com \
    --to=jacob.e.keller@intel.com \
    --cc=intel-wired-lan@osuosl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox