All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: <anthony.l.nguyen@intel.com>, <davem@davemloft.net>,
	<pabeni@redhat.com>, <edumazet@google.com>,
	<andrew+netdev@lunn.ch>, <netdev@vger.kernel.org>,
	<vinschen@redhat.com>, <alexander.nowlin@intel.com>,
	<larysa.zaremba@intel.com>
Subject: Re: [PATCH net 1/8] ice: fix UAF/NULL deref when VSI rebuild and XDP attach race
Date: Thu, 28 May 2026 11:14:15 +0200	[thread overview]
Message-ID: <ahgHZ8NNWPeFVsXr@boxer> (raw)
In-Reply-To: <20260523001616.1757210-1-kuba@kernel.org>

On Fri, May 22, 2026 at 05:16:16PM -0700, Jakub Kicinski wrote:
> This is an AI-generated review of your patch. The human sending this
> email has considered the AI review valid, or at least plausible.
> ---
> ice: fix UAF/NULL deref when VSI rebuild and XDP attach race
> 
> This commit addresses a race condition between a VSI rebuild and an XDP
> attach operation. It prevents rx_ring->xdp_prog from being populated before
> rx_ring->xdp_ring is valid by rejecting the XDP attach when a VSI rebuild
> is pending. XDP detachment is still permitted during this window to clear
> the existing program.
> 
> Fixes: 2504b8405768 ("ice: protect XDP configuration with a mutex")
> 
> > diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c
> > --- a/drivers/net/ethernet/intel/ice/ice_main.c
> > +++ b/drivers/net/ethernet/intel/ice/ice_main.c
> [ ... ]
> > @@ -2912,12 +2912,21 @@ ice_xdp_setup_prog(struct ice_vsi *vsi, struct bpf_prog *prog,
> >  	}
> >  
> >  	/* hot swap progs and avoid toggling link */
> > -	if (ice_is_xdp_ena_vsi(vsi) == !!prog ||
> > -	    test_bit(ICE_VSI_REBUILD_PENDING, vsi->state)) {
> > +	if (ice_is_xdp_ena_vsi(vsi) == !!prog) {
> >  		ice_vsi_assign_bpf_prog(vsi, prog);
> >  		return 0;
> >  	}
> >  
> > +	if (test_bit(ICE_VSI_REBUILD_PENDING, vsi->state)) {
> 
> [Severity: High]
> This is a pre-existing issue, but is the check for ICE_VSI_REBUILD_PENDING
> prone to a TOCTOU race because it relies on ad-hoc flag synchronization
> instead of proper locking with the device reset path?
> 
> The asynchronous reset path (ice_prepare_for_reset()) sets
> ICE_VSI_REBUILD_PENDING without holding vsi->xdp_state_lock or rtnl_lock().
> 
> If ice_xdp_setup_prog() (which holds both locks) checks the bit before it
> is set, it proceeds to configure XDP and sets ICE_VSI_DOWN. If the reset
> path then sets the bit and calls ice_pf_dis_all_vsi(), it will skip this
> VSI because ICE_VSI_DOWN is already set.
> 
> When ice_xdp_setup_prog() finishes, it calls ice_up() which clears
> ICE_VSI_DOWN and starts enabling hardware queues while the device is
> actively undergoing a hardware reset (ice_do_reset()).
> 
> Can writing to hardware registers during an active reset cause hardware
> hangs or PCI master aborts?
> 
> > +		if (prog) {
> > +			NL_SET_ERR_MSG_MOD(extack, "VSI rebuild is pending");
> > +			return -EAGAIN;
> > +		}
> > +
> > +		ice_vsi_assign_bpf_prog(vsi, NULL);
> 
> [Severity: High]
> This is a pre-existing issue, but does detaching an XDP program while a VSI
> rebuild has failed lead to a NULL pointer dereference here?
> 
> If a VSI rebuild fails, ice_vsi_decfg() frees vsi->rx_rings and sets the
> pointer to NULL via ice_vsi_free_arrays(), but leaves vsi->num_rxq
> non-zero. The ICE_VSI_REBUILD_PENDING bit remains set because it is only
> cleared on the success path in ice_vsi_rebuild().
> 
> If a user subsequently detaches XDP, ice_xdp_setup_prog() intercepts it
> because ICE_VSI_REBUILD_PENDING is set, and it calls
> ice_vsi_assign_bpf_prog(vsi, NULL).
> 
> This function loops up to vsi->num_rxq:
> 
> ice_vsi_assign_bpf_prog() {
>     ...
>     ice_for_each_rxq(vsi, i)
>         WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog);
>     ...
> }
> 
> Since vsi->rx_rings is NULL, does this cause a guaranteed NULL pointer
> dereference panic?

CC: Larysa

Seems we should check if vsi->rx_rings != NULL plus
ICE_VSI_REBUILD_PENDING should be cleared on error path in
ice_vsi_rebuild().

Do you have any comment on TOCTOU issue mentioned above?

> 
> > +		return 0;
> > +	}
> > +
> >  	if_running = netif_running(vsi->netdev) &&
> >  		     !test_and_set_bit(ICE_VSI_DOWN, vsi->state);
> -- 
> pw-bot: cr
> 

  reply	other threads:[~2026-05-28  9:14 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-20 18:34 [PATCH net 0/8][pull request] Intel Wired LAN Driver Updates 2026-05-20 (ice, iavf, i40e, ixgbe) Tony Nguyen
2026-05-20 18:34 ` [PATCH net 1/8] ice: fix UAF/NULL deref when VSI rebuild and XDP attach race Tony Nguyen
2026-05-21 15:37   ` Jakub Kicinski
2026-05-23  0:16   ` Jakub Kicinski
2026-05-28  9:14     ` Maciej Fijalkowski [this message]
2026-05-29  8:05       ` Larysa Zaremba
2026-06-01 12:21         ` Maciej Fijalkowski
2026-06-01 13:52           ` Larysa Zaremba
2026-05-20 18:34 ` [PATCH net 2/8] ice: fix stats array overflow when VF requests more queues Tony Nguyen
2026-05-23  0:16   ` Jakub Kicinski
2026-05-20 18:34 ` [PATCH net 3/8] iavf: return EBUSY if reset in progress or not ready during MAC change Tony Nguyen
2026-05-20 18:34 ` [PATCH net 4/8] i40e: skip unnecessary VF reset when setting trust Tony Nguyen
2026-05-23  0:16   ` Jakub Kicinski
2026-05-23  0:16   ` Jakub Kicinski
2026-05-20 18:34 ` [PATCH net 5/8] iavf: send MAC change request synchronously Tony Nguyen
2026-05-23  0:16   ` Jakub Kicinski
2026-05-23  0:16   ` Jakub Kicinski
2026-05-20 18:34 ` [PATCH net 6/8] ice: skip unnecessary VF reset when setting trust Tony Nguyen
2026-05-23  0:16   ` Jakub Kicinski
2026-05-23  0:16   ` Jakub Kicinski
2026-05-20 18:34 ` [PATCH net 7/8] i40e: set supported_extts_flags for rising edge Tony Nguyen
2026-05-23  0:16   ` Jakub Kicinski
2026-05-20 18:34 ` [PATCH net 8/8] ixgbe: only access vfinfo and mv_list under RCU lock Tony Nguyen
2026-05-23  0:16   ` Jakub Kicinski
2026-05-23  0:16   ` Jakub Kicinski

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=ahgHZ8NNWPeFVsXr@boxer \
    --to=maciej.fijalkowski@intel.com \
    --cc=alexander.nowlin@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=larysa.zaremba@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=vinschen@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.