mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Krishna Chaitanya Chundru <krishna.chundru@oss.qualcomm.com>
To: Lukas Wunner <lukas@wunner.de>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	manivannan.sadhasivam@oss.qualcomm.com,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] PCI: Fix NULL pointer access in pci_store_saved_state()
Date: Wed, 8 Apr 2026 15:16:28 +0530	[thread overview]
Message-ID: <89dda312-92ff-4957-bf67-dd0b60f681b8@oss.qualcomm.com> (raw)
In-Reply-To: <adIXJvrV1VRunFOu@wunner.de>



On 4/5/2026 1:32 PM, Lukas Wunner wrote:
> On Sat, Apr 04, 2026 at 02:23:00PM +0530, Krishna Chaitanya Chundru wrote:
>> If the PCIe link goes down while pci_save_state() is in progress, reads
>> from the device configuration space may return invalid values(all 0xF's).
> That should be harmless.  If the link goes down, the device should
> subsequently be de-enumerated by the hotplug driver.  If we save
> some bogus data before de-enumerating it, so be it.
>
> If the port above is not hotplug-capable, manual intervention is
> required for remove/rescan, but that's orthogonal to this problem.
we are seeing this issue in non hotplug-capable device.
>> One example is, while saving VC extended capability save path
>> (pci_save_vc_state() / pci_vc_do_save_buffer()) then interprets all-1s
>> capability fields as valid and ends up writing far beyond the allocated
>> pci_cap_saved_state buffer, corrupting the pci_dev->saved_cap_space list.
> I'm not familiar with drivers/pci/vc.c, but it seems it takes a size
> read from config space and uses it to write to a particular memory
> area?  That feels totally wrong, at the very least there should be
> a check for PCI_POSSIBLE_ERROR().
>
>> The link state check here is racy since the link may transition at any
>> time. This is a best-effort attempt to avoid saving PCI state when the
>> link is already down.
> No, please validate values read from config space with
> PCI_POSSIBLE_ERROR() before using them to access memory at
> a location that may be out-of-bounds.  Or cache the size on
> enumeration and avoid re-reading it upon pci_save_state().
This issue is coming as part of the probe, we are checking if the link is up first
and then trying to do pci_save_state() and when the execution is in the middle
save state we see there is a  linkdown and pci_save_state is actually storing
some all F's.  we are hitting the issue in pci_store_saved_state() which is
due wrong data saved as part of pci_save_state(). pci_save_state() has many
config reading having check for each read is not ideal way, that is why we are
tring to keep check so that it will not crash. - Krishna Chaitanya.
>
>> +	/*
>> +	 * The link state check here is racy since the link may transition at
>> +	 * any time. This is a best-effort attempt to avoid saving PCI state
>> +	 * when the link is already down.
>> +	 */
>> +	if (!pcie_link_is_active(dev)) {
>> +		dev->state_saved = false;
>> +		return NULL;
>> +	}
> The state_saved flag is only used by PM code to determine whether
> the driver called pci_save_state().  If it didn't, the PCI core
> will make up for it by calling pci_save_state().
>
> The state_saved flag is *not* an indication whether the saved state
> is usable and code outside power management has no business changing
> the flag's value.
ack.
> Thanks,
>
> Lukas


  reply	other threads:[~2026-04-08  9:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-04  8:52 [PATCH 0/2] " Krishna Chaitanya Chundru
2026-04-04  8:52 ` [PATCH 1/2] PCI: Add pcie_link_is_active() to determine if the link is active Krishna Chaitanya Chundru
2026-04-04  8:53 ` [PATCH 2/2] PCI: Fix NULL pointer access in pci_store_saved_state() Krishna Chaitanya Chundru
2026-04-05  8:02   ` Lukas Wunner
2026-04-08  9:46     ` Krishna Chaitanya Chundru [this message]
2026-04-08 10:59       ` Lukas Wunner

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=89dda312-92ff-4957-bf67-dd0b60f681b8@oss.qualcomm.com \
    --to=krishna.chundru@oss.qualcomm.com \
    --cc=bhelgaas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=manivannan.sadhasivam@oss.qualcomm.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®