mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Koichiro Den <den@valinux.co.jp>
To: zhangjiao2 <zhangjiao2@cmss.chinamobile.com>
Cc: ntb@lists.linux.dev, linux@treblig.org, jdmason@kudzu.us,
	 linux-kernel@vger.kernel.org, trivial@kernel.org
Subject: Re: [PATCH] NTB/msi: fix NULL deref when msi_first_desc() returns NULL
Date: Wed, 25 Nov 2026 14:00:56 +0900	[thread overview]
Message-ID: <awZj0FeJYoIS5_nE@z790sl> (raw)
In-Reply-To: <20261120083759.1887-1-zhangjiao2@cmss.chinamobile.com>

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
> 
> 
> 

      reply	other threads:[~2026-11-25  5:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  8:37 zhangjiao2
2026-11-25  5:00 ` Koichiro Den [this message]

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=awZj0FeJYoIS5_nE@z790sl \
    --to=den@valinux.co.jp \
    --cc=jdmason@kudzu.us \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@treblig.org \
    --cc=ntb@lists.linux.dev \
    --cc=trivial@kernel.org \
    --cc=zhangjiao2@cmss.chinamobile.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®