From: Ziming Du <duziming2@huawei.com>
To: <bhelgaas@google.com>
Cc: <linux-pci@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<liuyongqiang13@huawei.com>, <duziming2@huawei.com>
Subject: [PATCH v3 2/3] PCI: Prevent overflow in proc_bus_pci_write()
Date: Thu, 8 Jan 2026 09:59:43 +0800 [thread overview]
Message-ID: <20260108015944.3520719-3-duziming2@huawei.com> (raw)
In-Reply-To: <20260108015944.3520719-1-duziming2@huawei.com>
From: Yongqiang Liu <liuyongqiang13@huawei.com>
When the value of *ppos over the INT_MAX, the pos is over set to a
negative value which will be passed to get_user() or
pci_user_write_config_dword(). Unexpected behavior such as a soft lockup
will happen as follows:
watchdog: BUG: soft lockup - CPU#0 stuck for 130s! [syz.3.109:3444]
RIP: 0010:_raw_spin_unlock_irq+0x17/0x30
Call Trace:
<TASK>
pci_user_write_config_dword+0x126/0x1f0
proc_bus_pci_write+0x273/0x470
proc_reg_write+0x1b6/0x280
do_iter_write+0x48e/0x790
vfs_writev+0x125/0x4a0
__x64_sys_pwritev+0x1e2/0x2a0
do_syscall_64+0x59/0x110
entry_SYSCALL_64_after_hwframe+0x78/0xe2
Fix this by using unsigned int for the pos.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Yongqiang Liu <liuyongqiang13@huawei.com>
Signed-off-by: Ziming Du <duziming2@huawei.com>
---
drivers/pci/proc.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index 9348a0fb8084..2d51b26edbe7 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -113,10 +113,14 @@ 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;
+ int pos;
int size = dev->cfg_size;
int cnt, ret;
+ if (*ppos > INT_MAX)
+ return -EINVAL;
+ pos = *ppos;
+
ret = security_locked_down(LOCKDOWN_PCI_ACCESS);
if (ret)
return ret;
--
2.43.0
next prev parent reply other threads:[~2026-01-08 1:34 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-08 1:59 [PATCH v3 0/3] Miscellaneous fixes for pci subsystem Ziming Du
2026-01-08 1:59 ` [PATCH v3 1/3] PCI/sysfs: Fix null pointer dereference during hotplug Ziming Du
2026-01-08 1:59 ` Ziming Du [this message]
2026-01-08 11:35 ` [PATCH v3 2/3] PCI: Prevent overflow in proc_bus_pci_write() Ilpo Järvinen
2026-01-08 1:59 ` [PATCH v3 3/3] PCI/sysfs: Prohibit unaligned access to I/O port on non-x86 Ziming Du
2026-01-08 8:56 ` David Laight
2026-01-08 11:49 ` duziming
2026-01-09 7:21 ` Ilpo Järvinen
2026-01-09 9:40 ` duziming
2026-01-09 0:38 ` Maciej W. Rozycki
2026-01-09 12:53 ` David Laight
2026-01-09 15:25 ` Maciej W. Rozycki
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=20260108015944.3520719-3-duziming2@huawei.com \
--to=duziming2@huawei.com \
--cc=bhelgaas@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=liuyongqiang13@huawei.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.