{"id":2232234,"url":"http://patchwork.ozlabs.org/api/patches/2232234/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/patch/20260504022231.15501-1-kartikey406@gmail.com/","project":{"id":28,"url":"http://patchwork.ozlabs.org/api/projects/28/?format=json","name":"Linux PCI development","link_name":"linux-pci","list_id":"linux-pci.vger.kernel.org","list_email":"linux-pci@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260504022231.15501-1-kartikey406@gmail.com>","list_archive_url":null,"date":"2026-05-04T02:22:31","name":"[v2] PCI/proc: check user access return values in proc_bus_pci_{read,write}()","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"0a29cfa213bb8ca6363afdfe5b7f5f11a9bd387b","submitter":{"id":91725,"url":"http://patchwork.ozlabs.org/api/people/91725/?format=json","name":"Deepanshu Kartikey","email":"kartikey406@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-pci/patch/20260504022231.15501-1-kartikey406@gmail.com/mbox/","series":[{"id":502601,"url":"http://patchwork.ozlabs.org/api/series/502601/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/list/?series=502601","date":"2026-05-04T02:22:31","name":"[v2] PCI/proc: check user access return values in proc_bus_pci_{read,write}()","version":2,"mbox":"http://patchwork.ozlabs.org/series/502601/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2232234/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2232234/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-pci+bounces-53651-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-pci@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=A5mL4PjE;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=linux-pci+bounces-53651-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=\"A5mL4PjE\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.214.182","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=gmail.com"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org\n [IPv6:2600:3c0a:e001:db::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g855c5xBzz1y04\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 04 May 2026 12:22:44 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id 749A93006B3C\n\tfor <incoming@patchwork.ozlabs.org>; Mon,  4 May 2026 02:22:41 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id D12791C2324;\n\tMon,  4 May 2026 02:22:40 +0000 (UTC)","from mail-pl1-f182.google.com (mail-pl1-f182.google.com\n [209.85.214.182])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 684F113959D\n\tfor <linux-pci@vger.kernel.org>; Mon,  4 May 2026 02:22:39 +0000 (UTC)","by mail-pl1-f182.google.com with SMTP id\n d9443c01a7336-2b4650d5f5cso13088135ad.0\n        for <linux-pci@vger.kernel.org>; Sun, 03 May 2026 19:22:39 -0700 (PDT)","from deepanshu-kernel-hacker..\n ([2405:201:682f:383f:5d62:8570:2345:8a42])\n        by smtp.gmail.com with ESMTPSA id\n d9443c01a7336-2b9cae11fc3sm99505505ad.47.2026.05.03.19.22.35\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Sun, 03 May 2026 19:22:38 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777861360; cv=none;\n b=plCcdf1rs5zhjHXHXZbYeIyBqz2DWuKGrpPOkWRZ/Ml3S65/o05cy6RHXL5c+e6LCdDsjUNW0mTKyY8+1+xip3pbLtg8w+43cQN64CZq0KWklL+qU6cQHqoZdBL3wGM69sQBpg4jRUybJqEmpoVkQzv+ielcPPItXel8gBc74s0=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777861360; c=relaxed/simple;\n\tbh=vXczmFV5IBdVUa/CHv7/dKOn+w6DOjDWTr0mGGKKpjs=;\n\th=From:To:Cc:Subject:Date:Message-ID:MIME-Version;\n b=C3f1z34HreYNUNnAagqi8QWdtITNWOGLO3LCWS6VSHT8luQ3vGTLyIhFtZlOYHSyAXyxc9ibz+jkryR2SehINIeluDwaPAAYisyLWzu/ayrS8eS0ae77p3AoA4W82mYHI84XfexYnSssJuSMawgXmHRM0mj+Z5wosjF3yv8o/9Y=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com;\n spf=pass smtp.mailfrom=gmail.com;\n dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=A5mL4PjE; arc=none smtp.client-ip=209.85.214.182","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1777861359; x=1778466159;\n darn=vger.kernel.org;\n        h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n         :to:from:from:to:cc:subject:date:message-id:reply-to;\n        bh=11sBpNgZWAmpiT9L62gLgTLuG3EqsF6a4WTcpSvFCD0=;\n        b=A5mL4PjExaCsqhVD5U0H7dsSH5RFC/0jR2prusMOrfnb64B1HOAJUzsW+9ODVMT+b8\n         8u9dR9FRktalbL56pFYcnp2N08iQOuzwbK8NrBKVckfm0mlhP7BPTCczFtTlIHhAHMV+\n         sAm1n2xuFoyAurxO6V4WYL8PCDOkBEnUH8s10pslscr4WWFkWo6uLqisaKyL1m1rNMHO\n         uLq84ZjoY7T+KaGyH/mwpoEpeGlOM/y19cv0y4YGy5JPMx79SWtI76PQOUNK3O3X6C36\n         MxdylaW9tDKkuUx+gPq0Cp9srT0qTcmfilCStxm+qBxslDqrgZrORThF0YTMRsnbfahd\n         EdqA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1777861359; x=1778466159;\n        h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n         :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n         :message-id:reply-to;\n        bh=11sBpNgZWAmpiT9L62gLgTLuG3EqsF6a4WTcpSvFCD0=;\n        b=K5/Z3iBwozSe99iu1CW0UFYgzbEw5EocOqG2XDnyg7ccBDgRQS+a1w2RKIJZlkSTwT\n         HpK2/R4af3xHXwCD9vp7voyl3IjO1gksgm8VCbFyuxUPvferaxpAPxKPKDBvXxhBUQiP\n         sawT0oSsshnYknQw3Irg4MQhbDIkQOlFbYGr0OKR+ebtwJEaDEZFq5hl/yBgNoGfQavG\n         pC9fL7ND9fxfp+1+nAXjlwo5zdw8C91h1BueuZNyYp79RGiX984+y19kiKqpiUtrI37Q\n         oswbE8nHe4cecyDUeU8vdimECIVEMdjIt2hI+2I8yptRVXULg7InY96vrUULH8ABCqo+\n         Bosg==","X-Gm-Message-State":"AOJu0YxbJ3jlf7dUkEhr0Bujrdz0ze3/4ysPakQneOOxCp3PLZggSRaH\n\tmnvFKof6lvTbZhVr0lK5pl8jL5JcISi4FUP5+bPYobdT6x07//ZurHE9","X-Gm-Gg":"AeBDievsM2Va3EroupTRPeVvRe2CN5qTy3FRLtngmBShSneSjtk6mlA5mxqVSOZSenk\n\toZvJcYSqzXgHtnXqBlKoufkJLrdL4ys8xVCuXigUk4jv2YB9QxvnGeRacSg4re6jaPj9tGH4qLQ\n\tBDVuwtKI1xM+ajd3AKqj3X13/EuMy6ItnbE2MS9jVYHnyohCx78e3F+v45zqvBVIRyGI17HJSK2\n\texaFs4oObVSF7gYWzds2QScwJlnbq7zSOEHd3N62Tw+40kQFqul7KRYxVcf2UNZAleBVlJFKkJL\n\tzacRa/4jXRY82j3CL9YVT5H+dqVcbIwgvlntTXziFvY4Rc22XUB+fuNwO+J/zx+6IoQm44t6c+0\n\ts/A0STNUZWQwJGTv0r4GTYN34EKJYSFMX2ZFm+pYDm1D4g1Bsjy38x1H7qkEoyCr7aDtdFQ4ZnB\n\t1zXwbg+pGaxhlDOQ++WM+0cHgC/fr7fVjfplYLVhyCsgkjA/zP5h7hOvUA636CcoMMwjUd9/XMW\n\tHBQ+02pOh7pH5UBYg==","X-Received":"by 2002:a17:903:1585:b0:2b2:481b:de68 with SMTP id\n d9443c01a7336-2b9f2841e55mr75384995ad.35.1777861358669;\n        Sun, 03 May 2026 19:22:38 -0700 (PDT)","From":"Deepanshu Kartikey <kartikey406@gmail.com>","To":"bhelgaas@google.com,\n\tkw@linux.com","Cc":"linux-pci@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org,\n\tDeepanshu Kartikey <kartikey406@gmail.com>,\n\tsyzbot+c7604c9fdd7580cca4e0@syzkaller.appspotmail.com","Subject":"[PATCH v2] PCI/proc: check user access return values in\n 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-pci@vger.kernel.org","List-Id":"<linux-pci.vger.kernel.org>","List-Subscribe":"<mailto:linux-pci+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-pci+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit"},"content":"proc_bus_pci_write() ignores the return value of __get_user(). On a\nfaulting user pointer the extable fixup zeros the destination, and the\nfunction writes those zeros to PCI configuration space.\n\nsyzbot triggers this with writev()-ing a NULL iov_base to\n/proc/bus/pci/00/03.0 (the virtio-blk controller in the syzkaller VM):\nzero is written to the Command register, clearing Bus Master Enable,\nand the disk stops responding. In-flight journal writes never complete\nand jbd2 hangs in wait_on_buffer() indefinitely:\n\n  INFO: task jbd2/sda1-8 blocked in I/O wait for more than 143 seconds.\n   __wait_on_buffer fs/buffer.c:123\n   jbd2_journal_commit_transaction+0x388a/0x6870 fs/jbd2/commit.c:837\n   kjournald2 fs/jbd2/journal.c:201\n\nproc_bus_pci_read() has the symmetric problem with __put_user(): a\nfaulting user pointer silently drops config-space data and returns\nsuccess.\n\nSwitch both functions to get_user()/put_user(), which combine the\naccess_ok() check with the load/store and return -EFAULT on failure.\nThe up-front access_ok() can be removed accordingly. On error, jump to\na common label that releases the runtime-PM reference and returns\n-EFAULT.\n\nReported-by: syzbot+c7604c9fdd7580cca4e0@syzkaller.appspotmail.com\nCloses: https://syzkaller.appspot.com/bug?extid=c7604c9fdd7580cca4e0\nTested-by: syzbot+c7604c9fdd7580cca4e0@syzkaller.appspotmail.com\nSigned-off-by: Deepanshu Kartikey <kartikey406@gmail.com>\n---\nChanges in v2:\n - Use get_user()/put_user() and drop access_ok() (Krzysztof)\n - Rename label to err: per kernel convention (Krzysztof)\n - Simplify error path to release runtime-PM and return -EFAULT (Krzysztof)\n - Apply the same fix to proc_bus_pci_read() (Krzysztof)\n---\n drivers/pci/proc.c | 44 ++++++++++++++++++++++++++++----------------\n 1 file changed, 28 insertions(+), 16 deletions(-)","diff":"diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c\nindex ce36e35681e8..8e624d829840 100644\n--- a/drivers/pci/proc.c\n+++ b/drivers/pci/proc.c\n@@ -53,15 +53,13 @@ static ssize_t proc_bus_pci_read(struct file *file, char __user *buf,\n \t\tnbytes = size - pos;\n \tcnt = nbytes;\n \n-\tif (!access_ok(buf, cnt))\n-\t\treturn -EINVAL;\n-\n \tpci_config_pm_runtime_get(dev);\n \n \tif ((pos & 1) && cnt) {\n \t\tunsigned char val;\n \t\tpci_user_read_config_byte(dev, pos, &val);\n-\t\t__put_user(val, buf);\n+\t\tif (put_user(val, buf))\n+\t\t\tgoto err;\n \t\tbuf++;\n \t\tpos++;\n \t\tcnt--;\n@@ -70,7 +68,8 @@ static ssize_t proc_bus_pci_read(struct file *file, char __user *buf,\n \tif ((pos & 3) && cnt > 2) {\n \t\tunsigned short val;\n \t\tpci_user_read_config_word(dev, pos, &val);\n-\t\t__put_user(cpu_to_le16(val), (__le16 __user *) buf);\n+\t\tif (put_user(cpu_to_le16(val), (__le16 __user *) buf))\n+\t\t\tgoto err;\n \t\tbuf += 2;\n \t\tpos += 2;\n \t\tcnt -= 2;\n@@ -79,7 +78,8 @@ static ssize_t proc_bus_pci_read(struct file *file, char __user *buf,\n \twhile (cnt >= 4) {\n \t\tunsigned int val;\n \t\tpci_user_read_config_dword(dev, pos, &val);\n-\t\t__put_user(cpu_to_le32(val), (__le32 __user *) buf);\n+\t\tif (put_user(cpu_to_le32(val), (__le32 __user *) buf))\n+\t\t\tgoto err;\n \t\tbuf += 4;\n \t\tpos += 4;\n \t\tcnt -= 4;\n@@ -89,7 +89,8 @@ static ssize_t proc_bus_pci_read(struct file *file, char __user *buf,\n \tif (cnt >= 2) {\n \t\tunsigned short val;\n \t\tpci_user_read_config_word(dev, pos, &val);\n-\t\t__put_user(cpu_to_le16(val), (__le16 __user *) buf);\n+\t\tif (put_user(cpu_to_le16(val), (__le16 __user *) buf))\n+\t\t\tgoto err;\n \t\tbuf += 2;\n \t\tpos += 2;\n \t\tcnt -= 2;\n@@ -98,7 +99,8 @@ static ssize_t proc_bus_pci_read(struct file *file, char __user *buf,\n \tif (cnt) {\n \t\tunsigned char val;\n \t\tpci_user_read_config_byte(dev, pos, &val);\n-\t\t__put_user(val, buf);\n+\t\tif (put_user(val, buf))\n+\t\t\tgoto err;\n \t\tpos++;\n \t}\n \n@@ -106,6 +108,10 @@ static ssize_t proc_bus_pci_read(struct file *file, char __user *buf,\n \n \t*ppos = pos;\n \treturn nbytes;\n+\n+err:\n+\tpci_config_pm_runtime_put(dev);\n+\treturn -EFAULT;\n }\n \n static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf,\n@@ -129,14 +135,12 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf,\n \t\tnbytes = size - pos;\n \tcnt = nbytes;\n \n-\tif (!access_ok(buf, cnt))\n-\t\treturn -EINVAL;\n-\n \tpci_config_pm_runtime_get(dev);\n \n \tif ((pos & 1) && cnt) {\n \t\tunsigned char val;\n-\t\t__get_user(val, buf);\n+\t\tif (get_user(val, buf))\n+\t\t\tgoto err;\n \t\tpci_user_write_config_byte(dev, pos, val);\n \t\tbuf++;\n \t\tpos++;\n@@ -145,7 +149,8 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf,\n \n \tif ((pos & 3) && cnt > 2) {\n \t\t__le16 val;\n-\t\t__get_user(val, (__le16 __user *) buf);\n+\t\tif (get_user(val, (__le16 __user *) buf))\n+\t\t\tgoto err;\n \t\tpci_user_write_config_word(dev, pos, le16_to_cpu(val));\n \t\tbuf += 2;\n \t\tpos += 2;\n@@ -154,7 +159,8 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf,\n \n \twhile (cnt >= 4) {\n \t\t__le32 val;\n-\t\t__get_user(val, (__le32 __user *) buf);\n+\t\tif (get_user(val, (__le32 __user *) buf))\n+\t\t\tgoto err;\n \t\tpci_user_write_config_dword(dev, pos, le32_to_cpu(val));\n \t\tbuf += 4;\n \t\tpos += 4;\n@@ -163,7 +169,8 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf,\n \n \tif (cnt >= 2) {\n \t\t__le16 val;\n-\t\t__get_user(val, (__le16 __user *) buf);\n+\t\tif (get_user(val, (__le16 __user *) buf))\n+\t\t\tgoto err;\n \t\tpci_user_write_config_word(dev, pos, le16_to_cpu(val));\n \t\tbuf += 2;\n \t\tpos += 2;\n@@ -172,7 +179,8 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf,\n \n \tif (cnt) {\n \t\tunsigned char val;\n-\t\t__get_user(val, buf);\n+\t\tif (get_user(val, buf))\n+\t\t\tgoto err;\n \t\tpci_user_write_config_byte(dev, pos, val);\n \t\tpos++;\n \t}\n@@ -182,6 +190,10 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf,\n \t*ppos = pos;\n \ti_size_write(ino, dev->cfg_size);\n \treturn nbytes;\n+\n+err:\n+\tpci_config_pm_runtime_put(dev);\n+\treturn -EFAULT;\n }\n \n #ifdef HAVE_PCI_MMAP\n","prefixes":["v2"]}