All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: hangej <hangej@amazon.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v4] pci_crash: capture PCI config space at panic time
Date: Thu, 23 Jul 2026 19:10:26 +0000	[thread overview]
Message-ID: <20260723191027.3DF151F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260723185216.1089927-1-hangej@amazon.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] An out-of-bounds write corrupts the crash capture buffer if a device's cfg_size is not a 4-byte multiple.
--

--- Patch [1]: [PATCH v4] pci_crash: capture PCI config space at panic time ---
commit 453754eacce8780b38337ecf239a5ffdf63c4b25
Author: Johannes Hange <hangej@amazon.com>

pci_crash: capture PCI config space at panic time

This commit introduces a facility to capture PCI configuration space during
a kernel panic. It allocates a snapshot buffer updated via bus notifiers and
fills it using non-blocking config reads when a panic occurs. The resulting
buffer and pagemap are exported through VMCOREINFO for crash analysis.

> diff --git a/kernel/pci_crash.c b/kernel/pci_crash.c
> new file mode 100644
> --- /dev/null
> +++ b/kernel/pci_crash.c
[ ... ]
> +static void pci_crash_read_config_space(struct pci_dev *pdev, u8 *ptr,
> +					unsigned int cfg_size)
> +{
[ ... ]
> +	if (!pci_crash_endpoint_reachable(pdev)) {
> +		memset(cfg_data, 0xff, cfg_size);
> +		return;
> +	}
> +
> +	for (offset = 0; offset < cfg_size; offset += 4) {

[Severity: Medium]
Could this loop write out of bounds if cfg_size is unaligned?

Since this code executes during a panic where memory corruption is common,
pdev->cfg_size could potentially be corrupted to a value that is not a
multiple of 4. If that happens, the loop will unconditionally write 4 bytes
on its final iteration, which could overflow the allocated payload slice
for this device.

This might either corrupt the adjacent record's header or cause a double
fault if the final write crosses a vmalloc page boundary.

Would it make sense to align cfg_size down to a 4-byte boundary before
iterating, or clamp the final write to prevent it from going past the end
of the buffer?

> +		if (pci_bus_read_config_dword_trylock(pdev->bus, pdev->devfn,
> +						      offset, &val)) {
> +			put_unaligned_le32(0xFFFFFFFF, &cfg_data[offset]);
> +			continue;
> +		}
> +		put_unaligned_le32(val, &cfg_data[offset]);
> +	}
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260723185216.1089927-1-hangej@amazon.com?part=1

      reply	other threads:[~2026-07-23 19:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-23 18:49 [PATCH v4] pci_crash: capture PCI config space at panic time hangej
2026-07-23 19:10 ` sashiko-bot [this message]

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=20260723191027.3DF151F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=hangej@amazon.com \
    --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.