Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Alex Williamson <alex@shazbot.org>
To: Mohamad Raizudeen <raizudeen.kerneldev@gmail.com>
Cc: bhelgaas@google.com, skhan@linuxfoundation.org,
	jkoolstra@xs4all.nl, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org, alex@shazbot.org
Subject: Re: [PATCH] PCI: quirks: Fix out-of-bounds MMIO read in nvme_disable_and_flr()
Date: Wed, 2 Sep 2026 22:21:56 -0600	[thread overview]
Message-ID: <20260902222156.393e2457@shazbot.org> (raw)
In-Reply-To: <apjoiNcvvJLv2grA@kernel>

On Thu, 3 Sep 2026 08:54:56 +0530
Mohamad Raizudeen <raizudeen.kerneldev@gmail.com> wrote:

> On Wed, Sep 02, 2026 at 11:51:17AM -0600, Alex Williamson wrote:
> > On Mon, 17 Aug 2026 14:54:47 +0530
> > Mohamad Raizudeen <raizudeen.kerneldev@gmail.com> wrote:
> >   
> > > In nvme_disable_and_flr(), the PCI bar is mapped using
> > > NVME_REG_CC + sizeof(cfg) which is (0x14 + 4 = 0x18 bytes)
> > > 
> > > However, the function later reads the controller status from
> > > NVME_REG_CSTS - offset 0x1C, which is outside the mapped 0x18 byte
> > > boundary and it can cause a page fault or kernel panic on architectures
> > > that enforce strict MMIO boundaries.  
> > 
> > What are those architectures?  The bug and fix look correct, but the
> > risk seems overstated.  Thanks,
> > 
> > Alex
> >   
> Hi Alex,
> 
> Arm64, risc-v do panic on out-of-bounds mmio. But you are right that the
> risk is overstated, since most standard servers return all ones instead
> of crashing.

Are you building with some sort of sanity or debug checking enabled?

While we're clearly violating the API accessing beyond the requested
length, it's my understanding that we're generally working with
PAGE_SIZE mappings at the MMU, so unless we're crossing a page, the
access should work regardless.  Even for the cited archs.

The -1 return is typically related to how the platform handles
master-abort when accessing unimplemented or disabled MMIO space.  This
out-of-bounds access shouldn't be triggering that, it's still within
the enabled BAR range of the device.

Anyway, I'd be curious to see the backtrace and whether there's a
config option to enable such sanity checking.  Thanks,

Alex

> > > Fix this by increasing the mapping size to include NVME_REG_CSTS.
> > > 
> > > Fixes: ffb0863426eb9 ("PCI: Disable Samsung SM961/PM961 NVMe before FLR")
> > > Signed-off-by: Mohamad Raizudeen <raizudeen.kerneldev@gmail.com>
> > > ---
> > >  drivers/pci/quirks.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
> > > index b09f27f7846f..ed03892cc960 100644
> > > --- a/drivers/pci/quirks.c
> > > +++ b/drivers/pci/quirks.c
> > > @@ -4090,7 +4090,7 @@ static int nvme_disable_and_flr(struct pci_dev *dev, bool probe)
> > >  	if (probe)
> > >  		return 0;
> > >  
> > > -	bar = pci_iomap(dev, 0, NVME_REG_CC + sizeof(cfg));
> > > +	bar = pci_iomap(dev, 0, NVME_REG_CSTS + sizeof(cfg));
> > >  	if (!bar)
> > >  		return -ENOTTY;
> > >    
> >   


  reply	other threads:[~2026-09-03  4:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-17  9:24 [PATCH] PCI: quirks: Fix out-of-bounds MMIO read in nvme_disable_and_flr() Mohamad Raizudeen
2026-08-17  9:34 ` sashiko-bot
2026-09-02 17:51 ` Alex Williamson
2026-09-03  3:24   ` Mohamad Raizudeen
2026-09-03  4:21     ` Alex Williamson [this message]
2026-09-03  6:07       ` Mohamad Raizudeen

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=20260902222156.393e2457@shazbot.org \
    --to=alex@shazbot.org \
    --cc=bhelgaas@google.com \
    --cc=jkoolstra@xs4all.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=raizudeen.kerneldev@gmail.com \
    --cc=skhan@linuxfoundation.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