From: Alex Williamson <alex.williamson@redhat.com>
To: linux-pci@vger.kernel.org, bhelgaas@google.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] PCI: Fix double-free in resource attribute error path
Date: Tue, 16 Aug 2022 13:40:04 -0600 [thread overview]
Message-ID: <166067879638.1885802.1955389738707186135.stgit@omen> (raw)
In-Reply-To: <166067824399.1885802.12557332818208187324.stgit@omen>
If pci_create_attr() fails the remaining resource bin attributes are
removed and freed based on the pointer entries which are not cleared
in the case that creation of the bin attribute fails.
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
drivers/pci/pci-sysfs.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index fc804e08e3cb..9ac92e6a2397 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1196,8 +1196,14 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
res_attr->size = pci_resource_len(pdev, num);
res_attr->private = (void *)(unsigned long)num;
retval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr);
- if (retval)
+ if (retval) {
+ if (write_combine)
+ pdev->res_attr_wc[num] = NULL;
+ else
+ pdev->res_attr[num] = NULL;
+
kfree(res_attr);
+ }
return retval;
}
next prev parent reply other threads:[~2022-08-16 19:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-16 19:39 [PATCH 0/3] PCI: Expose resource resizing through sysfs Alex Williamson
2022-08-16 19:40 ` Alex Williamson [this message]
2022-08-16 19:40 ` [RFC PATCH 2/3] PCI: Skip reassigning bridge resources if reducing BAR size Alex Williamson
2022-08-16 19:41 ` [RFC PATCH 3/3] PCI: Expose PCIe Resizable BAR support via sysfs Alex Williamson
2022-08-17 10:10 ` [PATCH 0/3] PCI: Expose resource resizing through sysfs Christian König
2022-08-17 14:02 ` Alex Williamson
2022-08-18 11:16 ` Christian König
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=166067879638.1885802.1955389738707186135.stgit@omen \
--to=alex.williamson@redhat.com \
--cc=bhelgaas@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox