[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CALs4sv2aZUs097NXxNDyy7xJbdurPzFbODeFX5dJ=GBO5s3+Ew@mail.gmail.com>
Date: Tue, 6 Jan 2026 22:10:47 +0530
From: Pavan Chebbi <pavan.chebbi@...adcom.com>
To: Breno Leitao <leitao@...ian.org>
Cc: Michael Chan <michael.chan@...adcom.com>, Andrew Lunn <andrew+netdev@...n.ch>,
"David S. Miller" <davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Richard Cochran <richardcochran@...il.com>,
"Russell King (Oracle)" <rmk+kernel@...linux.org.uk>, Vadim Fedorenko <vadim.fedorenko@...ux.dev>,
Vladimir Oltean <vladimir.oltean@....com>, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org, kernel-team@...a.com, stable@...r.kernel.org
Subject: Re: [PATCH net v3] bnxt_en: Fix NULL pointer crash in bnxt_ptp_enable
during error cleanup
On Tue, Jan 6, 2026 at 8:01 PM Breno Leitao <leitao@...ian.org> wrote:
>
> When bnxt_init_one() fails during initialization (e.g.,
> bnxt_init_int_mode returns -ENODEV), the error path calls
> bnxt_free_hwrm_resources() which destroys the DMA pool and sets
> bp->hwrm_dma_pool to NULL. Subsequently, bnxt_ptp_clear() is called,
> which invokes ptp_clock_unregister().
>
> Since commit a60fc3294a37 ("ptp: rework ptp_clock_unregister() to
> disable events"), ptp_clock_unregister() now calls
> ptp_disable_all_events(), which in turn invokes the driver's .enable()
> callback (bnxt_ptp_enable()) to disable PTP events before completing the
> unregistration.
>
> bnxt_ptp_enable() attempts to send HWRM commands via bnxt_ptp_cfg_pin()
> and bnxt_ptp_cfg_event(), both of which call hwrm_req_init(). This
> function tries to allocate from bp->hwrm_dma_pool, causing a NULL
> pointer dereference:
>
> bnxt_en 0000:01:00.0 (unnamed net_device) (uninitialized): bnxt_init_int_mode err: ffffffed
> KASAN: null-ptr-deref in range [0x0000000000000028-0x000000000000002f]
> Call Trace:
> __hwrm_req_init (drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c:72)
> bnxt_ptp_enable (drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c:323 drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c:517)
> ptp_disable_all_events (drivers/ptp/ptp_chardev.c:66)
> ptp_clock_unregister (drivers/ptp/ptp_clock.c:518)
> bnxt_ptp_clear (drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c:1134)
> bnxt_init_one (drivers/net/ethernet/broadcom/bnxt/bnxt.c:16889)
>
> Lines are against commit f8f9c1f4d0c7 ("Linux 6.19-rc3")
>
> Fix this by clearing and unregistering ptp (bnxt_ptp_clear()) before
> freeing HWRM resources.
>
> Suggested-by: Pavan Chebbi <pavan.chebbi@...adcom.com>
> Signed-off-by: Breno Leitao <leitao@...ian.org>
> Fixes: a60fc3294a37 ("ptp: rework ptp_clock_unregister() to disable events")
> Cc: stable@...r.kernel.org
> ---
> Changes in v3:
> - Moved bp->ptp_cfg to be closer to the kfree(). (Pavan/Jakub)
> - Link to v2: https://patch.msgid.link/20260105-bnxt-v2-1-9ac69edef726@debian.org
>
> Changes in v2:
> - Instead of checking for HWRM resources in bnxt_ptp_enable(), call it
> when HWRM resources are availble (Pavan Chebbi)
> - Link to v1: https://patch.msgid.link/20251231-bnxt-v1-1-8f9cde6698b4@debian.org
> ---
> drivers/net/ethernet/broadcom/bnxt/bnxt.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> index d160e54ac121..8419d1eb4035 100644
> --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> @@ -16891,12 +16891,12 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
>
> init_err_pci_clean:
> bnxt_hwrm_func_drv_unrgtr(bp);
> - bnxt_free_hwrm_resources(bp);
> - bnxt_hwmon_uninit(bp);
> - bnxt_ethtool_free(bp);
> bnxt_ptp_clear(bp);
> kfree(bp->ptp_cfg);
> bp->ptp_cfg = NULL;
> + bnxt_free_hwrm_resources(bp);
> + bnxt_hwmon_uninit(bp);
> + bnxt_ethtool_free(bp);
> kfree(bp->fw_health);
> bp->fw_health = NULL;
> bnxt_cleanup_pci(bp);
>
> ---
> base-commit: e146b276a817807b8f4a94b5781bf80c6c00601b
> change-id: 20251231-bnxt-c54d317d8bfe
>
> Best regards,
> --
> Breno Leitao <leitao@...ian.org>
>
Thanks, Breno!
Reviewed-by: Pavan Chebbi <pavan.chebbi@...adcom.com>
Download attachment "smime.p7s" of type "application/pkcs7-signature" (5469 bytes)
Powered by blists - more mailing lists