]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
PCI/sysfs: Add CAP_SYS_ADMIN check to __resource_resize_store()
authorKrzysztof Wilczyński <kwilczynski@kernel.org>
Fri, 8 May 2026 04:35:24 +0000 (04:35 +0000)
committerBjorn Helgaas <bhelgaas@google.com>
Fri, 8 May 2026 22:56:25 +0000 (17:56 -0500)
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@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Tested-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://patch.msgid.link/20260508043543.217179-6-kwilczynski@kernel.org
drivers/pci/pci-sysfs.c

index 2280b7edb41f59a266370dfcd61be02ed0ac5e0e..dac780597727d47c9895bc1b79db21a98da17c6b 100644 (file)
@@ -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;