From: Deepanshu Kartikey <kartikey406@gmail.com>
To: bhelgaas@google.com, david.laight.linux@gmail.com
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
Deepanshu Kartikey <kartikey406@gmail.com>,
syzbot+7134530b25073b4ef373@syzkaller.appspotmail.com
Subject: [PATCH v2] PCI: sysfs: Reject unaligned resource I/O port accesses
Date: Mon, 28 Sep 2026 18:00:36 +0530 [thread overview]
Message-ID: <20260928123036.7902-1-kartikey406@gmail.com> (raw)
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
next reply other threads:[~2026-09-28 12:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 12:30 Deepanshu Kartikey [this message]
2026-09-28 12:39 ` [PATCH v2] PCI: sysfs: Reject unaligned resource I/O port accesses sashiko-bot
2026-09-28 12:57 ` Ilpo Järvinen
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=20260928123036.7902-1-kartikey406@gmail.com \
--to=kartikey406@gmail.com \
--cc=bhelgaas@google.com \
--cc=david.laight.linux@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.