All of lore.kernel.org
 help / color / mirror / Atom feed
From: syzbot <syzbot+c7604c9fdd7580cca4e0@syzkaller.appspotmail.com>
To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Forwarded: [PATCH] PCI/proc: check return value of __get_user() in proc_bus_pci_write()
Date: Fri, 01 May 2026 17:02:54 -0700	[thread overview]
Message-ID: <69f53f2e.050a0220.312cd3.001d.GAE@google.com> (raw)
In-Reply-To: <69f3f165.170a0220.5f1b.0010.GAE@google.com>

For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.

***

Subject: [PATCH] PCI/proc: check return value of __get_user() in proc_bus_pci_write()
Author: kartikey406@gmail.com

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master


proc_bus_pci_write() invokes __get_user() in five places without
checking its return value.  When the user pointer faults, the extable
fixup leaves the destination indeterminate but the function still hands
the value to pci_user_write_config_*(), writing fixup state to PCI
configuration space.

syzbot triggers this with a writev() whose iov_base is NULL on
/proc/bus/pci/00/03.0 (the virtio-blk controller in the syzkaller VM).
Every __get_user() faults, val ends up as fixup-zero, and zero is
written to config space offsets 0..6 -- including the Command register
at offset 4, clearing Bus Master and Memory Space Enable.  The disk
goes silent mid-flight, in-flight journal bios never complete, and
jbd2 hangs in wait_on_buffer() indefinitely:

  INFO: task jbd2/sda1-8:4955 blocked in I/O wait for more than 143 seconds.
   __wait_on_buffer fs/buffer.c:123
   jbd2_journal_commit_transaction+0x388a/0x6870 fs/jbd2/commit.c:837
   kjournald2 fs/jbd2/journal.c:201

Check the return value of every __get_user() and bail with -EFAULT on
failure, releasing the runtime-PM reference via a common exit path.

Reported-by: syzbot+c7604c9fdd7580cca4e0@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=c7604c9fdd7580cca4e0
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


  parent reply	other threads:[~2026-05-02  0:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-01  0:18 [syzbot] INFO: task jbd2/sda1-NUM:NUM blocked in I/O wait for more than NUM seconds syzbot
2026-05-01 14:48 ` [syzbot] [ext4?] " syzbot
2026-05-01 23:47 ` Forwarded: [PATCH] PCI/proc: validate user buffer before touching config space syzbot
2026-05-02  0:02 ` syzbot [this message]
2026-05-04  1:22 ` Forwarded: [PATCH v2] PCI/proc: check user access return values in proc_bus_pci_{read,write}() syzbot

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=69f53f2e.050a0220.312cd3.001d.GAE@google.com \
    --to=syzbot+c7604c9fdd7580cca4e0@syzkaller.appspotmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzkaller-bugs@googlegroups.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.