From: Deepanshu Kartikey <kartikey406@gmail.com>
To: bhelgaas@google.com
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
Deepanshu Kartikey <kartikey406@gmail.com>,
syzbot+c7604c9fdd7580cca4e0@syzkaller.appspotmail.com
Subject: [PATCH] PCI/proc: check __get_user() return value in proc_bus_pci_write()
Date: Sat, 2 May 2026 06:44:46 +0530 [thread overview]
Message-ID: <20260502011446.125268-1-kartikey406@gmail.com> (raw)
proc_bus_pci_write() does not check the return value of __get_user().
On a faulting user pointer the extable fixup zeros the destination,
and the function writes those zeros to PCI configuration space.
syzbot exploits this by writev()-ing a NULL iov_base to
/proc/bus/pci/00/03.0 (the virtio-blk controller in the syzkaller VM):
zero is written to the Command register, clearing Bus Master Enable,
and the disk stops responding. In-flight journal writes never complete
and jbd2 hangs in wait_on_buffer() indefinitely.
Check __get_user() and return -EFAULT on failure.
Reported-by: syzbot+c7604c9fdd7580cca4e0@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=c7604c9fdd7580cca4e0
Tested-by: syzbot+c7604c9fdd7580cca4e0@syzkaller.appspotmail.com
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
drivers/pci/proc.c | 33 +++++++++++++++++++++++++--------
1 file changed, 25 insertions(+), 8 deletions(-)
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index ce36e35681e8..54052157c276 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -136,7 +136,10 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf,
if ((pos & 1) && cnt) {
unsigned char val;
- __get_user(val, buf);
+ if (__get_user(val, buf)) {
+ ret = -EFAULT;
+ goto out;
+ }
pci_user_write_config_byte(dev, pos, val);
buf++;
pos++;
@@ -145,7 +148,10 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf,
if ((pos & 3) && cnt > 2) {
__le16 val;
- __get_user(val, (__le16 __user *) buf);
+ if (__get_user(val, (__le16 __user *) buf)) {
+ ret = -EFAULT;
+ goto out;
+ }
pci_user_write_config_word(dev, pos, le16_to_cpu(val));
buf += 2;
pos += 2;
@@ -154,7 +160,10 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf,
while (cnt >= 4) {
__le32 val;
- __get_user(val, (__le32 __user *) buf);
+ if (__get_user(val, (__le32 __user *) buf)) {
+ ret = -EFAULT;
+ goto out;
+ }
pci_user_write_config_dword(dev, pos, le32_to_cpu(val));
buf += 4;
pos += 4;
@@ -163,7 +172,10 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf,
if (cnt >= 2) {
__le16 val;
- __get_user(val, (__le16 __user *) buf);
+ if (__get_user(val, (__le16 __user *) buf)) {
+ ret = -EFAULT;
+ goto out;
+ }
pci_user_write_config_word(dev, pos, le16_to_cpu(val));
buf += 2;
pos += 2;
@@ -172,16 +184,21 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf,
if (cnt) {
unsigned char val;
- __get_user(val, buf);
+ if (__get_user(val, buf)) {
+ ret = -EFAULT;
+ goto out;
+ }
pci_user_write_config_byte(dev, pos, val);
pos++;
}
+ ret = nbytes;
+out:
pci_config_pm_runtime_put(dev);
-
*ppos = pos;
- i_size_write(ino, dev->cfg_size);
- return nbytes;
+ if (ret > 0)
+ i_size_write(ino, dev->cfg_size);
+ return ret;
}
#ifdef HAVE_PCI_MMAP
--
2.43.0
next reply other threads:[~2026-05-02 1:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-02 1:14 Deepanshu Kartikey [this message]
2026-05-03 18:46 ` [PATCH] PCI/proc: check __get_user() return value in proc_bus_pci_write() Krzysztof Wilczyński
2026-05-04 1:23 ` Deepanshu Kartikey
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=20260502011446.125268-1-kartikey406@gmail.com \
--to=kartikey406@gmail.com \
--cc=bhelgaas@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=syzbot+c7604c9fdd7580cca4e0@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox