From nobody Sun Jun 14 04:09:17 2026 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 7A2DA1A0BF3 for ; Mon, 4 May 2026 02:22:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777861362; cv=none; b=YE7Relmvm8SBxoTfO9OsmdIed2yppc1apGR7JJOyS9o6k1MYsEod9uSiCsD3fdYhI8AvRkt4SPUdzuqve9uXBJRUVkdFfC4Yh942Y/BfufSAwbV+NQMNHwdk2y+1UucIN9PmfWOOfps6YrEGwvzgZI7h1sPFzTBrDV3R2i59ayg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777861362; c=relaxed/simple; bh=vXczmFV5IBdVUa/CHv7/dKOn+w6DOjDWTr0mGGKKpjs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Py2+dJwPPI8NIvIQ+CwFh0s36iDIh0tfj6RL/IAP2O9qDEVs3dv1o8rbCO4RTXpHRe2YMLuTYAd1CLWPIae8YSchx3WGqSbbeGj1yZXgdZlQ3aBEPwTviI0pYXaBMGgmho0ZIBd832NQbDIO9RuPhigUd4nNPwG+gooehlBo+sU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=A5mL4PjE; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="A5mL4PjE" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2ba0714574fso4636465ad.2 for ; Sun, 03 May 2026 19:22:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777861359; x=1778466159; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=11sBpNgZWAmpiT9L62gLgTLuG3EqsF6a4WTcpSvFCD0=; b=A5mL4PjExaCsqhVD5U0H7dsSH5RFC/0jR2prusMOrfnb64B1HOAJUzsW+9ODVMT+b8 8u9dR9FRktalbL56pFYcnp2N08iQOuzwbK8NrBKVckfm0mlhP7BPTCczFtTlIHhAHMV+ sAm1n2xuFoyAurxO6V4WYL8PCDOkBEnUH8s10pslscr4WWFkWo6uLqisaKyL1m1rNMHO uLq84ZjoY7T+KaGyH/mwpoEpeGlOM/y19cv0y4YGy5JPMx79SWtI76PQOUNK3O3X6C36 MxdylaW9tDKkuUx+gPq0Cp9srT0qTcmfilCStxm+qBxslDqrgZrORThF0YTMRsnbfahd EdqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777861359; x=1778466159; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=11sBpNgZWAmpiT9L62gLgTLuG3EqsF6a4WTcpSvFCD0=; b=X+0CGXT9N3WfG39eMivgz0naScJY8YDihh/5ljz+sHH5O1lx/XnpFvN+4ZCP72RE5f w/RjcQipKgY8lrCx+ZGSCpRRuCb5982vFNKDChuUX3ldfiAjb5Rowk7aUtLwoitylOC2 pGH3pqD+Jd3f57jzJYZ9Z4QhrFVjqIy8S3RnkO/fiA4jskXx0Z0fIvTsDOQyE5iOVUW2 O69lHfb7HDJ6m8ljt2+lfIBn/90bd8WCuIXI3EilAUM+adY+MIxTkgOLKgSPUj+f5/Hu vX/2Gppv9y6IErS5tqPoF3UT7dKMwQfnjqhZuPqXumYp9GqiYQBSZFG8nD+ZN/JzeENq M+Vw== X-Forwarded-Encrypted: i=1; AFNElJ9S4a/O8/WaRYK/D6E1X2eBKMB3L20wOs/Vjc7dje9ZNYnpomFlzCTp1FFoBC+l1zaMDaQsT+PITfl5e6Q=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0DSg+SuNLgnqq3uvGBMmWwx2FP5QvYB96a25VHoFsmiEqu0QX XMIqQ4PsuE5gjJVRk0F3aayIpx7OnFAlnIV2T+NwjI8w4Xkd9q66BWwH X-Gm-Gg: AeBDiete4Smeam0BCijrxuUqy4jS6ieiYdgtoDKHU57V9lNpH3RZHOQmYYSr5AzoEN5 wWTBjASffDDcLBaQS+Jg3inIQKp9MjLsggtkJlKGOFuOgd4APNARu3akSzzhF/HvOX0UAXTS3nS 0jfZkw6txlMS9KQIvq7oJ2ahmcSSqRqfa2R9aHpDZdwgkYR7I4Kd3sdF50CKRtgj6X26Rc42cR1 X51T7Sj584lPCRml8SYnRpyxFcKK4nd4s0CgapbCTgLUhaUkZvVo4NdSJx83hgvCm+69LMOoSwG mcLHawUV+QUMoN/0whKVEXKkBWQbc9L3l5lknkkiL9hs1boeXI9fzzyP/yY+A1977QDch9Fw+aD ohD/ZdXfM7rEh/vCOB5XFFgO/0dC12nTKJmkbzm0VoUPYFUdN6Qc/IZnBHvvTKil0xZCzK8Zd3Q Y3+bSkO+4cZ/Chyyoegy9UEN74UfroAKBRGHc6Z8eDUfS1JbgkDx0SrToawno5DRe9XWQq+B3w8 ZcUlKCUJIWKEpxAsw== X-Received: by 2002:a17:903:1585:b0:2b2:481b:de68 with SMTP id d9443c01a7336-2b9f2841e55mr75384995ad.35.1777861358669; Sun, 03 May 2026 19:22:38 -0700 (PDT) Received: from deepanshu-kernel-hacker.. ([2405:201:682f:383f:5d62:8570:2345:8a42]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b9cae11fc3sm99505505ad.47.2026.05.03.19.22.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 May 2026 19:22:38 -0700 (PDT) From: Deepanshu Kartikey To: bhelgaas@google.com, kw@linux.com Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Deepanshu Kartikey , syzbot+c7604c9fdd7580cca4e0@syzkaller.appspotmail.com Subject: [PATCH v2] PCI/proc: check user access return values in proc_bus_pci_{read,write}() Date: Mon, 4 May 2026 07:52:31 +0530 Message-ID: <20260504022231.15501-1-kartikey406@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" proc_bus_pci_write() ignores 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 triggers this with 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: INFO: task jbd2/sda1-8 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 with __put_user(): a faulting user pointer silently drops config-space data and returns success. Switch both functions to get_user()/put_user(), which combine the access_ok() check with the load/store and return -EFAULT on failure. The up-front access_ok() can be removed accordingly. On error, jump to a common label that releases the runtime-PM reference and returns -EFAULT. Reported-by: syzbot+c7604c9fdd7580cca4e0@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3Dc7604c9fdd7580cca4e0 Tested-by: syzbot+c7604c9fdd7580cca4e0@syzkaller.appspotmail.com Signed-off-by: Deepanshu Kartikey --- Changes in v2: - Use get_user()/put_user() and drop access_ok() (Krzysztof) - Rename label to err: per kernel convention (Krzysztof) - Simplify error path to release runtime-PM and return -EFAULT (Krzysztof) - Apply the same fix to proc_bus_pci_read() (Krzysztof) --- drivers/pci/proc.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c index ce36e35681e8..8e624d829840 100644 --- a/drivers/pci/proc.c +++ b/drivers/pci/proc.c @@ -53,15 +53,13 @@ static ssize_t proc_bus_pci_read(struct file *file, cha= r __user *buf, nbytes =3D size - pos; cnt =3D nbytes; =20 - if (!access_ok(buf, cnt)) - return -EINVAL; - pci_config_pm_runtime_get(dev); =20 if ((pos & 1) && cnt) { unsigned char val; pci_user_read_config_byte(dev, pos, &val); - __put_user(val, buf); + if (put_user(val, buf)) + goto err; buf++; pos++; cnt--; @@ -70,7 +68,8 @@ static ssize_t proc_bus_pci_read(struct file *file, char = __user *buf, if ((pos & 3) && cnt > 2) { unsigned short val; pci_user_read_config_word(dev, pos, &val); - __put_user(cpu_to_le16(val), (__le16 __user *) buf); + if (put_user(cpu_to_le16(val), (__le16 __user *) buf)) + goto err; buf +=3D 2; pos +=3D 2; cnt -=3D 2; @@ -79,7 +78,8 @@ static ssize_t proc_bus_pci_read(struct file *file, char = __user *buf, while (cnt >=3D 4) { unsigned int val; pci_user_read_config_dword(dev, pos, &val); - __put_user(cpu_to_le32(val), (__le32 __user *) buf); + if (put_user(cpu_to_le32(val), (__le32 __user *) buf)) + goto err; buf +=3D 4; pos +=3D 4; cnt -=3D 4; @@ -89,7 +89,8 @@ static ssize_t proc_bus_pci_read(struct file *file, char = __user *buf, if (cnt >=3D 2) { unsigned short val; pci_user_read_config_word(dev, pos, &val); - __put_user(cpu_to_le16(val), (__le16 __user *) buf); + if (put_user(cpu_to_le16(val), (__le16 __user *) buf)) + goto err; buf +=3D 2; pos +=3D 2; cnt -=3D 2; @@ -98,7 +99,8 @@ static ssize_t proc_bus_pci_read(struct file *file, char = __user *buf, if (cnt) { unsigned char val; pci_user_read_config_byte(dev, pos, &val); - __put_user(val, buf); + if (put_user(val, buf)) + goto err; pos++; } =20 @@ -106,6 +108,10 @@ static ssize_t proc_bus_pci_read(struct file *file, ch= ar __user *buf, =20 *ppos =3D pos; return nbytes; + +err: + pci_config_pm_runtime_put(dev); + return -EFAULT; } =20 static ssize_t proc_bus_pci_write(struct file *file, const char __user *bu= f, @@ -129,14 +135,12 @@ static ssize_t proc_bus_pci_write(struct file *file, = const char __user *buf, nbytes =3D size - pos; cnt =3D nbytes; =20 - if (!access_ok(buf, cnt)) - return -EINVAL; - pci_config_pm_runtime_get(dev); =20 if ((pos & 1) && cnt) { unsigned char val; - __get_user(val, buf); + if (get_user(val, buf)) + goto err; pci_user_write_config_byte(dev, pos, val); buf++; pos++; @@ -145,7 +149,8 @@ static ssize_t proc_bus_pci_write(struct file *file, co= nst char __user *buf, =20 if ((pos & 3) && cnt > 2) { __le16 val; - __get_user(val, (__le16 __user *) buf); + if (get_user(val, (__le16 __user *) buf)) + goto err; pci_user_write_config_word(dev, pos, le16_to_cpu(val)); buf +=3D 2; pos +=3D 2; @@ -154,7 +159,8 @@ static ssize_t proc_bus_pci_write(struct file *file, co= nst char __user *buf, =20 while (cnt >=3D 4) { __le32 val; - __get_user(val, (__le32 __user *) buf); + if (get_user(val, (__le32 __user *) buf)) + goto err; pci_user_write_config_dword(dev, pos, le32_to_cpu(val)); buf +=3D 4; pos +=3D 4; @@ -163,7 +169,8 @@ static ssize_t proc_bus_pci_write(struct file *file, co= nst char __user *buf, =20 if (cnt >=3D 2) { __le16 val; - __get_user(val, (__le16 __user *) buf); + if (get_user(val, (__le16 __user *) buf)) + goto err; pci_user_write_config_word(dev, pos, le16_to_cpu(val)); buf +=3D 2; pos +=3D 2; @@ -172,7 +179,8 @@ static ssize_t proc_bus_pci_write(struct file *file, co= nst char __user *buf, =20 if (cnt) { unsigned char val; - __get_user(val, buf); + if (get_user(val, buf)) + goto err; pci_user_write_config_byte(dev, pos, val); pos++; } @@ -182,6 +190,10 @@ static ssize_t proc_bus_pci_write(struct file *file, c= onst char __user *buf, *ppos =3D pos; i_size_write(ino, dev->cfg_size); return nbytes; + +err: + pci_config_pm_runtime_put(dev); + return -EFAULT; } =20 #ifdef HAVE_PCI_MMAP --=20 2.43.0