Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH] PCI/sysfs: Add lockdown checks to legacy I/O and memory handlers
@ 2026-07-20 21:15 Krzysztof Wilczyński
  2026-07-20 21:25 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Krzysztof Wilczyński @ 2026-07-20 21:15 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Bjorn Helgaas, Manivannan Sadhasivam, Lorenzo Pieralisi,
	Kees Cook, Matthew Garrett, linux-pci

Currently, the legacy I/O and memory sysfs handlers do not
check security_locked_down(LOCKDOWN_PCI_ACCESS), leaving the
legacy_io and legacy_mem files unprotected when the kernel is
locked down.

Commit eb627e17727e ("PCI: Lock down BAR access when the
kernel is locked down") added the check to pci_write_config(),
pci_mmap_resource(), and pci_write_resource_io() to prevent
userspace from programming DMA-capable hardware that could be
used to modify kernel code, but did not cover the legacy
handlers.

As a result, root can still write arbitrary I/O ports and map
the legacy I/O and memory spaces while the kernel is locked
down, which is the same capability the lockdown is meant to
remove.

Thus, add the same check to pci_write_legacy_io(),
pci_mmap_legacy_mem(), and pci_mmap_legacy_io().

These generic handlers cover both architectures that
define HAVE_PCI_LEGACY (such as Alpha and PowerPC).

Fixes: eb627e17727e ("PCI: Lock down BAR access when the kernel is locked down")
Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
---
 drivers/pci/pci-sysfs.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 5ec0b245a69b..c24d9270a7a5 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -913,6 +913,11 @@ static ssize_t pci_write_legacy_io(struct file *filp, struct kobject *kobj,
 				   char *buf, loff_t off, size_t count)
 {
 	struct pci_bus *bus = to_pci_bus(kobj_to_dev(kobj));
+	int ret;
+
+	ret = security_locked_down(LOCKDOWN_PCI_ACCESS);
+	if (ret)
+		return ret;
 
 	/* Only support 1, 2 or 4 byte accesses */
 	if (count != 1 && count != 2 && count != 4)
@@ -937,6 +942,11 @@ static int pci_mmap_legacy_mem(struct file *filp, struct kobject *kobj,
 			       struct vm_area_struct *vma)
 {
 	struct pci_bus *bus = to_pci_bus(kobj_to_dev(kobj));
+	int ret;
+
+	ret = security_locked_down(LOCKDOWN_PCI_ACCESS);
+	if (ret)
+		return ret;
 
 	return pci_mmap_legacy_page_range(bus, vma, pci_mmap_mem);
 }
@@ -957,6 +967,11 @@ static int pci_mmap_legacy_io(struct file *filp, struct kobject *kobj,
 			      struct vm_area_struct *vma)
 {
 	struct pci_bus *bus = to_pci_bus(kobj_to_dev(kobj));
+	int ret;
+
+	ret = security_locked_down(LOCKDOWN_PCI_ACCESS);
+	if (ret)
+		return ret;
 
 	return pci_mmap_legacy_page_range(bus, vma, pci_mmap_io);
 }
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] PCI/sysfs: Add lockdown checks to legacy I/O and memory handlers
  2026-07-20 21:15 [PATCH] PCI/sysfs: Add lockdown checks to legacy I/O and memory handlers Krzysztof Wilczyński
@ 2026-07-20 21:25 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-07-20 21:25 UTC (permalink / raw)
  To: Krzysztof Wilczyński; +Cc: linux-pci

> Currently, the legacy I/O and memory sysfs handlers do not
> check security_locked_down(LOCKDOWN_PCI_ACCESS), leaving the
> legacy_io and legacy_mem files unprotected when the kernel is
> locked down.
> 
> Commit eb627e17727e ("PCI: Lock down BAR access when the
> kernel is locked down") added the check to pci_write_config(),
> pci_mmap_resource(), and pci_write_resource_io() to prevent
> userspace from programming DMA-capable hardware that could be
> used to modify kernel code, but did not cover the legacy
> handlers.
> 
> As a result, root can still write arbitrary I/O ports and map
> the legacy I/O and memory spaces while the kernel is locked
> down, which is the same capability the lockdown is meant to
> remove.
> 
> Thus, add the same check to pci_write_legacy_io(),
> pci_mmap_legacy_mem(), and pci_mmap_legacy_io().
> 
> These generic handlers cover both architectures that
> define HAVE_PCI_LEGACY (such as Alpha and PowerPC).
> 
> Fixes: eb627e17727e ("PCI: Lock down BAR access when the kernel is locked down")
> Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>

Sashiko has reviewed this patch and found no issues. It looks great!

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-20 21:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-20 21:15 [PATCH] PCI/sysfs: Add lockdown checks to legacy I/O and memory handlers Krzysztof Wilczyński
2026-07-20 21:25 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox