From: Ziming Du <duziming2@huawei.com>
To: <bhelgaas@google.com>, <kwilczynski@kernel.org>
Cc: <rientjes@google.com>, <gregkh@suse.de>, <iweiny@kernel.org>,
<djbw@kernel.org>, <Jonathan.Cameron@huawei.com>,
<linux-pci@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<liuyongqiang13@huawei.com>, <duziming2@huawei.com>
Subject: [PATCH v2 1/6] PCI: Prevent overflow in proc_bus_pci_{read,write}()
Date: Thu, 30 Jul 2026 11:24:33 +0800 [thread overview]
Message-ID: <20260730032438.1643450-2-duziming2@huawei.com> (raw)
In-Reply-To: <20260730032438.1643450-1-duziming2@huawei.com>
proc_bus_pci_read() and proc_bus_pci_write() receive the file position
as a 64-bit loff_t, but store it in 32-bit variables before validating
the configuration-space bounds.
In proc_bus_pci_read(), pos is an unsigned int, so an offset such as
0x100000000 is truncated to zero. The truncated value passes the bounds
check and causes the function to read from the beginning of PCI
configuration space instead of returning EOF.
In proc_bus_pci_write(), pos is an int, so an offset greater than
INT_MAX may become negative. The negative value bypasses the
pos >= size check and is then mixed with the unsigned nbytes value.
The bounds adjustment may consequently expand a small request into a
very large transfer, causing the write loop to use invalid negative
configuration offsets and run for an excessive amount of time.
Fix this by changing the type of pos to loff_t.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Suggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Yongqiang Liu <liuyongqiang13@huawei.com>
Signed-off-by: Ziming Du <duziming2@huawei.com>
---
drivers/pci/proc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index 71ad289fcb8e3..cad749924dd89 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -30,7 +30,7 @@ static ssize_t proc_bus_pci_read(struct file *file, char __user *buf,
size_t nbytes, loff_t *ppos)
{
struct pci_dev *dev = pde_data(file_inode(file));
- unsigned int pos = *ppos;
+ loff_t pos = *ppos;
unsigned int cnt, size;
/*
@@ -114,7 +114,7 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf,
{
struct inode *ino = file_inode(file);
struct pci_dev *dev = pde_data(ino);
- int pos = *ppos;
+ loff_t pos = *ppos;
int size = dev->cfg_size;
int cnt, ret;
--
2.43.0
next prev parent reply other threads:[~2026-07-30 3:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 3:24 [PATCH v2 0/6] PCI: Fix procfs PCI config access issues Ziming Du
2026-07-30 3:24 ` Ziming Du [this message]
2026-07-30 3:24 ` [PATCH v2 2/6] PCI/proc: Serialize config inode size updates Ziming Du
2026-07-30 3:24 ` [PATCH v2 3/6] PCI/proc: Warn on writes to driver-exclusive config regions Ziming Du
2026-07-30 3:24 ` [PATCH v2 4/6] PCI/sysfs: Avoid runtime PM at config-space EOF Ziming Du
2026-07-30 3:24 ` [PATCH v2 5/6] PCI: Align proc_bus_pci_write() with pci_write_config() Ziming Du
2026-07-30 3:24 ` [PATCH v2 6/6] PCI: Align proc_bus_pci_read() with pci_read_config() Ziming Du
2026-08-17 6:22 ` [PING] PCI: Fix procfs PCI config access issues duziming
2026-10-12 2:27 ` duziming
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=20260730032438.1643450-2-duziming2@huawei.com \
--to=duziming2@huawei.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=bhelgaas@google.com \
--cc=djbw@kernel.org \
--cc=gregkh@suse.de \
--cc=iweiny@kernel.org \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=liuyongqiang13@huawei.com \
--cc=rientjes@google.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®