All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Bjorn Helgaas <bhelgaas@google.com>, Hans de Goede <hdegoede@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	linux-pci@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [PATCH] x86/PCI: Fix use after free in pci_acpi_root_prepare_resources()
Date: Tue, 1 Mar 2022 11:10:10 +0300	[thread overview]
Message-ID: <20220301081010.GA17375@kili> (raw)

The resource_list_destroy_entry() function frees "entry", so move the
dereferences before the free.

Fixes: 62fabd56faaf ("x86/PCI: Disable exclusion of E820 reserved addresses in some cases")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 arch/x86/pci/acpi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
index e4617df661a9..fa89ffba2e51 100644
--- a/arch/x86/pci/acpi.c
+++ b/arch/x86/pci/acpi.c
@@ -357,14 +357,14 @@ static int pci_acpi_root_prepare_resources(struct acpi_pci_root_info *ci)
 	status = acpi_pci_probe_root_resources(ci);
 	if (pci_use_crs) {
 		resource_list_for_each_entry_safe(entry, tmp, &ci->resources) {
-			if (resource_is_pcicfg_ioport(entry->res))
-				resource_list_destroy_entry(entry);
 			if (resource_is_efi_mmio_region(entry->res)) {
 				dev_info(&device->dev,
 					"host bridge window %pR is marked by EFI as MMIO\n",
 					entry->res);
 				pci_use_e820 = false;
 			}
+			if (resource_is_pcicfg_ioport(entry->res))
+				resource_list_destroy_entry(entry);
 		}
 		return status;
 	}
-- 
2.20.1


             reply	other threads:[~2022-03-01  8:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-01  8:10 Dan Carpenter [this message]
2022-03-01 11:22 ` [PATCH] x86/PCI: Fix use after free in pci_acpi_root_prepare_resources() Hans de Goede

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=20220301081010.GA17375@kili \
    --to=dan.carpenter@oracle.com \
    --cc=bhelgaas@google.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hdegoede@redhat.com \
    --cc=hpa@zytor.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=mingo@redhat.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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.