Linux PCI Non-Transparent Bridge framework and drivers
 help / color / mirror / Atom feed
* Re: [PATCH] NTB/msi: fix NULL deref when msi_first_desc() returns NULL
       [not found] <20261120083759.1887-1-zhangjiao2@cmss.chinamobile.com>
@ 2026-11-25  5:00 ` Koichiro Den
  0 siblings, 0 replies; only message in thread
From: Koichiro Den @ 2026-11-25  5:00 UTC (permalink / raw)
  To: zhangjiao2; +Cc: ntb, linux, jdmason, linux-kernel, trivial

On Fri, Nov 20, 2026 at 04:37:58PM +0800, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> 
> msi_first_desc() can return NULL if no MSI descriptors are found,
> but ntb_msi_setup_mws() dereferences desc->msg unconditionally
> inside the scoped_guard block. Add a NULL check and return -ENODEV
> to prevent a null pointer dereference.
> 
> Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>

Would it make more sense if we would add a pci_dev_msi_enabled(ntb->pdev) check
in the ntb_msi_init() function entry? By doing so, that fruitless and unsafe
ntb_msi_setup_mws() attempt would not run in the first place and IMO the code
base would be more readable/maintainable.

(Even so, I personally think the NULL check you are trying to add is good,
perhaps with WARN_ON, but whether such defensive programming makes sense is up
to the NTB maintainers, I suppose.)

By the way, ntb@lists.linux.dev is missing in To: or Cc:. Let me add it.

Best regards,
Koichiro Den

> ---
>  drivers/ntb/msi.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/ntb/msi.c b/drivers/ntb/msi.c
> index 13e9f52ec8cc..cfe2125b2fe0 100644
> --- a/drivers/ntb/msi.c
> +++ b/drivers/ntb/msi.c
> @@ -108,6 +108,8 @@ int ntb_msi_setup_mws(struct ntb_dev *ntb)
>  
>  	scoped_guard (msi_descs_lock, &ntb->pdev->dev) {
>  		desc = msi_first_desc(&ntb->pdev->dev, MSI_DESC_ASSOCIATED);
> +		if (!desc)
> +			return -ENODEV;
>  		addr = desc->msg.address_lo + ((uint64_t)desc->msg.address_hi << 32);
>  	}
>  
> -- 
> 2.33.0
> 
> 
> 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-25  5:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261120083759.1887-1-zhangjiao2@cmss.chinamobile.com>
2026-11-25  5:00 ` [PATCH] NTB/msi: fix NULL deref when msi_first_desc() returns NULL Koichiro Den

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox