[PATCH AUTOSEL 6.18-6.12] PCI/sysfs: Add CAP_SYS_ADMIN check to __resource_resize_store()

From: Sasha Levin

Date: Mon Aug 31 2026 - 12:15:14 EST


From: Krzysztof Wilczyński <kwilczynski@xxxxxxxxxx>

[ Upstream commit 25ec7f57deceec633f27bc93b615f951e2ade814 ]

Currently, the __resource_resize_store() allows writing to the
resourceN_resize sysfs attribute to change a BAR's size without checking
for capabilities, currently relying only on the file access check.

Resizing a BAR modifies PCI device configuration and can disrupt active
drivers. After the upcoming conversion to static attributes, it will also
trigger resource file updates via sysfs_update_groups().

Add a CAP_SYS_ADMIN check to prevent unprivileged users from performing BAR
resize operations.

Signed-off-by: Krzysztof Wilczyński <kwilczynski@xxxxxxxxxx>
Signed-off-by: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>
Tested-by: Shivaprasad G Bhat <sbhat@xxxxxxxxxxxxx>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
Link: https://patch.msgid.link/20260508043543.217179-6-kwilczynski@xxxxxxxxxx
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---

LLM Generated explanations, may be completely bogus:

The background searches finished. Here’s what they turned up:

- **`b4 dig`** — Exited successfully but produced no output. The fix
isn’t in this checkout, and `b4 dig` needs a commit hash, so the lore
thread wasn’t resolved that way. Patch context came from the local v7
mbox and Patchwork mirrors instead.
- **Git history (`resourceN_resize` / `__resource_resize_store`)** — In
this shallow 6.18.43 tree, both only surface as merge commit
`5d324e5159d9e`; the original introduction isn’t reachable here. The
ABI doc (September 2022) is the best dating we have for when the sysfs
interface landed.

That doesn’t change the earlier conclusion: the missing `CAP_SYS_ADMIN`
check is present in this tree, the fix is small and standalone, and the
backport recommendation remains **YES** for 6.18.y.

drivers/pci/pci-sysfs.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index edb9bc34c0c58..990994db752ab 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1575,6 +1575,9 @@ static ssize_t __resource_resize_store(struct device *dev, int n,
int ret;
u16 cmd;

+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
if (kstrtoul(buf, 0, &size) < 0)
return -EINVAL;

--
2.53.0