All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Krzysztof Wilczyński" <kwilczynski@kernel.org>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH] PCI/proc: Warn on writes to kernel-exclusive config space regions
Date: Wed, 29 Jul 2026 08:13:06 +0000	[thread overview]
Message-ID: <20260729081307.11AA71F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260729075413.1215821-1-kwilczynski@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Integer truncation of the 64-bit file offset to a 32-bit signed int allows bypassing bounds checks and the new exclusive region check, leading to massive out-of-bounds memory writes.
--

--- Patch [1]: [PATCH] PCI/proc: Warn on writes to kernel-exclusive config space regions ---
commit ae079df2d52cc5cc8959cf281ed5e461ff2fcfd8
Author: Krzysztof Wilczyński <kwilczynski@kernel.org>

PCI/proc: Warn on writes to kernel-exclusive config space regions

This patch updates proc_bus_pci_write() to check if a user space write
targets a kernel-exclusive config space region. If so, it emits a warning
and taints the kernel, bringing the procfs interface to parity with the
sysfs interface.

> diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
> index 71ad289fcb8e3..12200979d3a82 100644
> --- a/drivers/pci/proc.c
> +++ b/drivers/pci/proc.c
[ ... ]
> @@ -122,6 +124,12 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf,
>  	if (ret)
>  		return ret;
>  
> +	if (resource_is_exclusive(&dev->driver_exclusive_resource, pos, nbytes)) {
> +		pci_warn_once(dev, "%s: Unexpected write to kernel-exclusive config offset %x",
> +			      current->comm, pos);
> +		add_taint(TAINT_USER, LOCKDEP_STILL_OK);
> +	}
> +

[Severity: High]
This is a pre-existing issue, but does truncating the 64-bit file offset to a
32-bit signed integer earlier in proc_bus_pci_write() allow bypassing this
new exclusive region check?

A large positive 64-bit file offset provided via pwrite64() gets truncated to
a negative value:

drivers/pci/proc.c:proc_bus_pci_write() {
    ...
	int pos = *ppos;
    ...
}

Because resource_is_exclusive() takes a u64 address, the negative pos will
sign-extend into a massive 64-bit value that won't match any exclusive
region, bypassing this detection entirely.

Additionally, this truncation also bypasses the subsequent bounds checks:

	if (pos >= size)
		return 0;
	if (nbytes >= size)
		nbytes = size;
	if (pos + nbytes > size)
		nbytes = size - pos;

The signed comparison if (pos >= size) evaluates to false for a negative
pos. Because nbytes is unsigned, the length clipping if (pos + nbytes > size)
evaluates using unsigned arithmetic and becomes true for a negative pos. This
erroneously increases nbytes up to massive out-of-bounds lengths, potentially
leading to large writes outside the PCI configuration space.

>  	if (pos >= size)
>  		return 0;
>  	if (nbytes >= size)

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260729075413.1215821-1-kwilczynski@kernel.org?part=1

  reply	other threads:[~2026-07-29  8:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29  7:54 [PATCH] PCI/proc: Warn on writes to kernel-exclusive config space regions Krzysztof Wilczyński
2026-07-29  8:13 ` sashiko-bot [this message]
2026-08-01  4:06 ` Krzysztof Wilczyński

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=20260729081307.11AA71F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kwilczynski@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.