mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Deepanshu Kartikey <kartikey406@gmail.com>
Cc: bhelgaas@google.com, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] PCI: sysfs: Reject unaligned resource I/O port accesses
Date: Sun, 18 Oct 2026 15:31:01 +0100	[thread overview]
Message-ID: <20261018153101.59d276f5@pumpkin> (raw)
In-Reply-To: <CADhLXY6Pb9Y5f9r12RZA1bbjBS_ctXAkXHPwY8qWwn_1WOJAsA@mail.gmail.com>

On Sun, 18 Oct 2026 16:30:19 +0530
Deepanshu Kartikey <kartikey406@gmail.com> wrote:

> On Mon, Sep 28, 2026 at 6:00 PM Deepanshu Kartikey
> <kartikey406@gmail.com> wrote:
> >
> > pci_resource_io() validates that the requested port lies within the
> > BAR but never checks that it is aligned to the access size. A
> > pwrite64()/pread64() on a resourceN file with an odd offset and
> > count=2 or count=4 reaches outw()/outl() with a misaligned address.
> > On arm64 this becomes a store/load to a Device-memory mapping
> > (PCI_IOBASE + port), which architecturally requires natural
> > alignment, causing an alignment fault and kernel oops.
> >
> > Reject misaligned 2- and 4-byte accesses before they reach the
> > low-level accessor. With natural alignment enforced, an access that
> > starts inside the BAR cannot extend past its end, so drop the
> > port + count - 1 range check.
> >
> > Reported-by: syzbot+7134530b25073b4ef373@syzkaller.appspotmail.com
> > Closes: https://syzkaller.appspot.com/bug?extid=7134530b25073b4ef373
> > Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
> > ---
> > v2: Check alignment per access size in the case 2/case 4 branches
> >     instead of using IS_ALIGNED() with a user-controlled count, and
> >     drop the now-redundant port + count - 1 range check.
> >     (Bjorn, David, sashiko)
> > ---
> >  drivers/pci/pci-sysfs.c | 7 ++++---
> >  1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> > index 1f21856aac8a..8118cc6b3a61 100644
> > --- a/drivers/pci/pci-sysfs.c
> > +++ b/drivers/pci/pci-sysfs.c
> > @@ -1209,9 +1209,6 @@ static ssize_t pci_resource_io(struct file *filp, struct kobject *kobj,
> >         if (port > pci_resource_end(pdev, bar))
> >                 return 0;
> >
> > -       if (port + count - 1 > pci_resource_end(pdev, bar))
> > -               return -EINVAL;
> > -
> >         switch (count) {
> >         case 1:
> >                 if (write)
> > @@ -1220,12 +1217,16 @@ static ssize_t pci_resource_io(struct file *filp, struct kobject *kobj,
> >                         *(u8 *)buf = inb(port);
> >                 return 1;
> >         case 2:
> > +               if (port & 1)
> > +                       return -EINVAL;
> >                 if (write)
> >                         outw(*(u16 *)buf, port);
> >                 else
> >                         *(u16 *)buf = inw(port);
> >                 return 2;
> >         case 4:
> > +               if (port & 3)
> > +                       return -EINVAL;
> >                 if (write)
> >                         outl(*(u32 *)buf, port);
> >                 else
> > --
> > 2.43.0
> >  
> 
> Hi David,
> 
> Gentle Reminder. Please let me know the status of this patch.

You need to prod the relevant maintainer, not me.

David

> 
> Thanks
> 
> Deepanshu


      reply	other threads:[~2026-10-18 14:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28 12:30 Deepanshu Kartikey
2026-09-28 12:57 ` Ilpo Järvinen
2026-09-28 18:17   ` David Laight
2026-10-18 11:00 ` Deepanshu Kartikey
2026-10-18 14:31   ` David Laight [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=20261018153101.59d276f5@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=kartikey406@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.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

all inboxes | Powered by JetHome®