Forwarded: Re: [syzbot] [pci?] BUG: unable to handle kernel paging request in pci_resource_io

syzbot posted 1 patch 1 month, 3 weeks ago
Forwarded: Re: [syzbot] [pci?] BUG: unable to handle kernel paging request in pci_resource_io
Posted by syzbot 1 month, 3 weeks ago
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.

***

Subject: Re: [syzbot] [pci?] BUG: unable to handle kernel paging request in pci_resource_io
Author: rihyeon8648@gmail.com

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git ba5cc80fd32665ed609037ff30ede8d194f24aab

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 5ec0b24..2aba909 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1175,6 +1175,16 @@ static ssize_t pci_resource_io(struct file *filp, struct kobject *kobj,
 	if (port + count - 1 > pci_resource_end(pdev, bar))
 		return -EINVAL;

+	/*
+	 * Architectures that have no separate I/O address space emulate port
+	 * I/O with an MMIO window at PCI_IOBASE, so @port becomes an address
+	 * in a Device memory mapping.  Unaligned accesses to Device memory
+	 * fault there, and @port is fully controlled by the file offset, so
+	 * require the access to be naturally aligned.
+	 */
+	if (!IS_ALIGNED(port, count))
+		return -EINVAL;
+
 	switch (count) {
 	case 1:
 		if (write)