From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f71.google.com (mail-oo1-f71.google.com [209.85.161.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4915337BA6 for ; Fri, 1 May 2026 23:47:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.71 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777679255; cv=none; b=Ll0FhOLTrSfbnZjUfiAD2VEX2ozMFFjPU20syqrd6ahJl5qKHnGdt5Po3o73xzhO+8HFmrg2RvmNZhP7/uNIgV0W5+BDnZ0pizSQoH6s/qmIsDrB04e+KvVVmSZveec+NEB76W7hhi4WD4xHYUtS4zQLUSUu0Vps4FeTILY21E4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777679255; c=relaxed/simple; bh=VcZdbNIEa1YCGSQtoWUUALyZd1AA102JpyPaeWwbi30=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=RQDZCZ1hPcBF9oOszam+AF+rNvO2sDcoLVZwC3LShrAiWQrcKJjgKJAYtS/lvl9mIaZPR7HiYv0szHcpEzdHDViRrpDZQffppC46FTIQG+rCs6XrxmAxx1K+MqNpLg5dg6S+wl8H7D5VOlkNJKOOWeMpeI2pVx16ugYhiDjRdug= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.161.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-oo1-f71.google.com with SMTP id 006d021491bc7-6853c2438b9so5264771eaf.3 for ; Fri, 01 May 2026 16:47:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777679253; x=1778284053; h=to:from:subject:message-id:in-reply-to:date:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iKhkZm38EIGD7l6j5FDT5UpnPM+T2AUCjRF4Mp5ya8U=; b=cqxE5r6mqOQtqRQsL8dULLkECQcW6HH/i8IVsky8yfp8n4CWtc8WxY87j5K2Y/Ya15 J3ab34ZkL/+r/H8f3aJFo6xFuAYxaU4/47CTqiyT2uoJ765RyJvhV+UEhR5wXV5qS/XO FOaOivaCcJD+vgQI942XtKY6hCAP7n5GCLBY0D1jE3k4L+E584PSK4uk6y4XhbZ2I0Ln 65+nbFCu2BinTDpikf7Sl1ILep1ukra2bVFf0cot4wf3Vh2pHjQ2CDThAF9RBG00ki2W e6rO8Irk//xPD+M4AARfRT2PUX1OgGueoZE4oYeEnpCiSI1nYlGiDnEg7e82se9Evy0m MFGA== X-Gm-Message-State: AOJu0YxeE659UoW4EkHN6DX98YVhXAbyV4edAZrnV2sIR/ge+frqc4ua ocfhZcDjtzS5nF3H7OfhZynYodMoIL2mlG9iliykD4z97GG8kSOI14Lspd90s/B0a/pb8C1Ct+M NE+29X/b/28GzNKhlTgNNB2txH/oc+fsE5vnG5Ip4DOVZaNtAuRpxxKX8C00= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a4a:e913:0:b0:694:8c67:5cb6 with SMTP id 006d021491bc7-69697df6987mr634418eaf.41.1777679252882; Fri, 01 May 2026 16:47:32 -0700 (PDT) Date: Fri, 01 May 2026 16:47:32 -0700 In-Reply-To: <69f3f165.170a0220.5f1b.0010.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <69f53b94.050a0220.312cd3.001b.GAE@google.com> Subject: Forwarded: [PATCH] PCI/proc: validate user buffer before touching config space From: syzbot To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8" For archival purposes, forwarding an incoming command email to linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com. *** Subject: [PATCH] PCI/proc: validate user buffer before touching config space 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() repeatedly 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 proc_bus_pci_read() has the symmetric problem: an unchecked __put_user() into a faulting user pointer silently drops config-space data. Fix both by staging through a kernel buffer. The write path uses memdup_user() to copy the user buffer up front; a bad user pointer now returns -EFAULT before any device state is touched, and the function no longer races a concurrent userspace mutation of the buffer across successive __get_user()s. The read path collects config-space data into a kmalloc'd buffer and copy_to_user()s it once at the end. Reported-by: syzbot+c7604c9fdd7580cca4e0@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=c7604c9fdd7580cca4e0 Signed-off-by: Deepanshu Kartikey --- drivers/pci/proc.c | 78 ++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c index ce36e35681e8..aa54c4e1445d 100644 --- a/drivers/pci/proc.c +++ b/drivers/pci/proc.c @@ -31,13 +31,14 @@ static ssize_t proc_bus_pci_read(struct file *file, char __user *buf, struct pci_dev *dev = pde_data(file_inode(file)); unsigned int pos = *ppos; unsigned int cnt, size; + void *kbuf; + u8 *kp; /* * Normal users can read only the standardized portion of the * configuration space as several chips lock up when trying to read * undefined locations (think of Intel PIIX4 as a typical example). */ - if (capable(CAP_SYS_ADMIN)) size = dev->cfg_size; else if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) @@ -53,57 +54,61 @@ static ssize_t proc_bus_pci_read(struct file *file, char __user *buf, nbytes = size - pos; cnt = nbytes; - if (!access_ok(buf, cnt)) - return -EINVAL; + kbuf = kmalloc(cnt, GFP_KERNEL); + if (!kbuf) + return -ENOMEM; + kp = kbuf; pci_config_pm_runtime_get(dev); if ((pos & 1) && cnt) { - unsigned char val; - pci_user_read_config_byte(dev, pos, &val); - __put_user(val, buf); - buf++; + pci_user_read_config_byte(dev, pos, kp); + kp++; pos++; cnt--; } if ((pos & 3) && cnt > 2) { - unsigned short val; + u16 val; pci_user_read_config_word(dev, pos, &val); - __put_user(cpu_to_le16(val), (__le16 __user *) buf); - buf += 2; + *(__le16 *)kp = cpu_to_le16(val); + kp += 2; pos += 2; cnt -= 2; } while (cnt >= 4) { - unsigned int val; + u32 val; pci_user_read_config_dword(dev, pos, &val); - __put_user(cpu_to_le32(val), (__le32 __user *) buf); - buf += 4; + *(__le32 *)kp = cpu_to_le32(val); + kp += 4; pos += 4; cnt -= 4; cond_resched(); } if (cnt >= 2) { - unsigned short val; + u16 val; pci_user_read_config_word(dev, pos, &val); - __put_user(cpu_to_le16(val), (__le16 __user *) buf); - buf += 2; + *(__le16 *)kp = cpu_to_le16(val); + kp += 2; pos += 2; cnt -= 2; } if (cnt) { - unsigned char val; - pci_user_read_config_byte(dev, pos, &val); - __put_user(val, buf); + pci_user_read_config_byte(dev, pos, kp); pos++; } pci_config_pm_runtime_put(dev); + if (copy_to_user(buf, kbuf, nbytes)) { + kfree(kbuf); + return -EFAULT; + } + kfree(kbuf); + *ppos = pos; return nbytes; } @@ -116,6 +121,8 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf, int pos = *ppos; int size = dev->cfg_size; int cnt, ret; + const u8 *kp; + u8 *kbuf; ret = security_locked_down(LOCKDOWN_PCI_ACCESS); if (ret) @@ -129,56 +136,53 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf, nbytes = size - pos; cnt = nbytes; - if (!access_ok(buf, cnt)) - return -EINVAL; + kbuf = memdup_user(buf, cnt); + if (IS_ERR(kbuf)) + return PTR_ERR(kbuf); + kp = kbuf; pci_config_pm_runtime_get(dev); if ((pos & 1) && cnt) { - unsigned char val; - __get_user(val, buf); - pci_user_write_config_byte(dev, pos, val); - buf++; + pci_user_write_config_byte(dev, pos, *kp); + kp++; pos++; cnt--; } if ((pos & 3) && cnt > 2) { - __le16 val; - __get_user(val, (__le16 __user *) buf); + __le16 val = *(const __le16 *)kp; pci_user_write_config_word(dev, pos, le16_to_cpu(val)); - buf += 2; + kp += 2; pos += 2; cnt -= 2; } while (cnt >= 4) { - __le32 val; - __get_user(val, (__le32 __user *) buf); + __le32 val = *(const __le32 *)kp; pci_user_write_config_dword(dev, pos, le32_to_cpu(val)); - buf += 4; + kp += 4; pos += 4; cnt -= 4; } if (cnt >= 2) { - __le16 val; - __get_user(val, (__le16 __user *) buf); + __le16 val = *(const __le16 *)kp; pci_user_write_config_word(dev, pos, le16_to_cpu(val)); - buf += 2; + kp += 2; pos += 2; cnt -= 2; } if (cnt) { - unsigned char val; - __get_user(val, buf); - pci_user_write_config_byte(dev, pos, val); + pci_user_write_config_byte(dev, pos, *kp); pos++; } pci_config_pm_runtime_put(dev); + kfree(kbuf); + *ppos = pos; i_size_write(ino, dev->cfg_size); return nbytes; -- 2.43.0