From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Deepanshu Kartikey <kartikey406@gmail.com>
Cc: bhelgaas@google.com, david.laight.linux@gmail.com,
linux-pci@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
syzbot+7134530b25073b4ef373@syzkaller.appspotmail.com
Subject: Re: [PATCH v2] PCI: sysfs: Reject unaligned resource I/O port accesses
Date: Mon, 28 Sep 2026 15:57:23 +0300 (EEST) [thread overview]
Message-ID: <fd1753ec-020b-b90d-ec1a-9d21ab2fa9a4@linux.intel.com> (raw)
In-Reply-To: <20260928123036.7902-1-kartikey406@gmail.com>
On Mon, 28 Sep 2026, Deepanshu Kartikey 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)
Why fon't these use !IS_ALIGNED() anymore? You can use e.g. sizeof() to
connect it to the natural alignment of the type so you don't have to use
literals at all.
> + return -EINVAL;
> if (write)
> outl(*(u32 *)buf, port);
> else
>
--
i.
next prev parent reply other threads:[~2026-09-28 12:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 12:30 Deepanshu Kartikey
2026-09-28 12:57 ` Ilpo Järvinen [this message]
2026-09-28 18:17 ` David Laight
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=fd1753ec-020b-b90d-ec1a-9d21ab2fa9a4@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=bhelgaas@google.com \
--cc=david.laight.linux@gmail.com \
--cc=kartikey406@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=syzbot+7134530b25073b4ef373@syzkaller.appspotmail.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®