Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH] PCI: sysfs: Reject unaligned resource I/O port accesses
@ 2026-08-09  4:59 Deepanshu Kartikey
  2026-08-09  5:16 ` sashiko-bot
  2026-08-09  7:16 ` Rihyeon Kim
  0 siblings, 2 replies; 3+ messages in thread
From: Deepanshu Kartikey @ 2026-08-09  4:59 UTC (permalink / raw)
  To: bhelgaas
  Cc: linux-pci, linux-kernel, Deepanshu Kartikey,
	syzbot+7134530b25073b4ef373

pci_resource_io() validates that off+count stays within the BAR's
range but never checks that the resulting port 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 accesses before they reach the low-level accessor.

Reported-by: syzbot+7134530b25073b4ef373@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=7134530b25073b4ef373
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
 drivers/pci/pci-sysfs.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 5ec0b245a69b..72f0404a34e9 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1175,6 +1175,9 @@ static ssize_t pci_resource_io(struct file *filp, struct kobject *kobj,
 	if (port + count - 1 > pci_resource_end(pdev, bar))
 		return -EINVAL;
 
+	if (!IS_ALIGNED(port, count))
+		return -EINVAL;
+
 	switch (count) {
 	case 1:
 		if (write)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-08-09  7:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-09  4:59 [PATCH] PCI: sysfs: Reject unaligned resource I/O port accesses Deepanshu Kartikey
2026-08-09  5:16 ` sashiko-bot
2026-08-09  7:16 ` Rihyeon Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox