From: Krzysztof Wilczyński Date: Fri, 8 May 2026 04:35:24 +0000 (+0000) Subject: PCI/sysfs: Add CAP_SYS_ADMIN check to __resource_resize_store() X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=25ec7f57deceec633f27bc93b615f951e2ade814;p=thirdparty%2Fkernel%2Flinux.git PCI/sysfs: Add CAP_SYS_ADMIN check to __resource_resize_store() 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 Signed-off-by: Bjorn Helgaas Tested-by: Shivaprasad G Bhat Reviewed-by: Ilpo Järvinen Link: https://patch.msgid.link/20260508043543.217179-6-kwilczynski@kernel.org --- diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 2280b7edb41f..dac780597727 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1596,6 +1596,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;