mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
To: Haotian Zhang <vulab@iscas.ac.cn>,
	Jacob Keller <jacob.e.keller@intel.com>,
	Matthew Wilcox <willy@infradead.org>
Cc: Tony Nguyen <anthony.l.nguyen@intel.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	<intel-wired-lan@lists.osuosl.org>, <netdev@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] ice: ice_adapter: release xa entry on adapter allocation failure
Date: Wed, 1 Oct 2025 07:29:14 +0200	[thread overview]
Message-ID: <ccc138d2-fa93-43f2-9733-e461396db769@intel.com> (raw)
In-Reply-To: <20250930015125.617-1-vulab@iscas.ac.cn>

On 9/30/25 03:51, Haotian Zhang wrote:
> When ice_adapter_new() fails, the reserved XArray entry created by
> xa_insert() is not released. This causes subsequent insertions at
> the same index to return -EBUSY, potentially leading to
> NULL pointer dereferences.
> 
> Release the reserved entry with xa_release() when adapter allocation
> fails to prevent this issue.
> 
> Fixes: 0f0023c649c7 ("ice: do not init struct ice_adapter more times than needed")
> Suggested-by: Jacob Keller <jacob.e.keller@intel.com>
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
> 
> ---
> Changes in v2:
>    - Instead of checking the return value of xa_store(), fix the real bug
>      where a failed ice_adapter_new() would leave a stale entry in the
>      XArray.
>    - Use xa_release() to clean up the reserved entry, as suggested by
>      Jacob Keller.

this is a correct improvement, but please let me propose other options,
with 2. being my favorite:

1. (just ice changes)
change the call order to be:
(note that it is under a mutex)
xa_load() // return early if another adapter exists
xa_reserve() // return early if no mem
ice_adapter_new() // return early if err
xa_store()


2. (xarray changes)
(perhaps I'm biased as the one introducing the error on error path):
change xa_insert() to return 0 or -EEXIST when used as a reserving call
(IOW: caller wanted to reserve, entry is reserved, so return should be 0
(or -EEXIST if we really want to differentiate in the callers)).


> ---
>   drivers/net/ethernet/intel/ice/ice_adapter.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/intel/ice/ice_adapter.c b/drivers/net/ethernet/intel/ice/ice_adapter.c
> index b53561c34708..9eb100b11439 100644
> --- a/drivers/net/ethernet/intel/ice/ice_adapter.c
> +++ b/drivers/net/ethernet/intel/ice/ice_adapter.c
> @@ -110,8 +110,10 @@ struct ice_adapter *ice_adapter_get(struct pci_dev *pdev)
>   			return ERR_PTR(err);
>   
>   		adapter = ice_adapter_new(pdev);
> -		if (!adapter)
> +		if (!adapter) {
> +			xa_release(&ice_adapters, index);
>   			return ERR_PTR(-ENOMEM);
> +		}
>   		xa_store(&ice_adapters, index, adapter, GFP_KERNEL);
>   	}
>   	return adapter;


  reply	other threads:[~2025-10-01  5:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20250929024855.2037-1-vulab@iscas.ac.cn>
2025-09-30  1:51 ` Haotian Zhang
2025-10-01  5:29   ` Przemek Kitszel [this message]
2025-10-01 22:00     ` 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=ccc138d2-fa93-43f2-9733-e461396db769@intel.com \
    --to=przemyslaw.kitszel@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=jacob.e.keller@intel.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=vulab@iscas.ac.cn \
    --cc=willy@infradead.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

Powered by JetHome