Re: [PATCH] PCI/sysfs: Prohibit unaligned access to I/O port

From: Krzysztof Wilczyński

Date: Sun May 03 2026 - 16:34:17 EST


Hello,

> diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> index 16eaaf749ba97..c88910bcad262 100644
> --- a/drivers/pci/pci-sysfs.c
> +++ b/drivers/pci/pci-sysfs.c
> @@ -31,6 +31,7 @@
> #include <linux/of.h>
> #include <linux/aperture.h>
> #include <linux/unaligned.h>
> +#include <linux/align.h>
> #include "pci.h"

The "pci.h" header includes "linux/align.h" already.

> #ifndef ARCH_PCI_DEV_GROUPS
> @@ -1157,6 +1158,9 @@ static ssize_t pci_resource_io(struct file *filp, struct kobject *kobj,
> if (port + count - 1 > pci_resource_end(pdev, bar))
> return -EINVAL;
>
> + if (!IS_ALIGNED(port, count))
> + return -EINVAL;
> +
> switch (count) {
> case 1:
> if (write)

Otherwise:

Reviewed-by: Krzysztof Wilczyński <kwilczynski@xxxxxxxxxx>

Thank you!

Krzysztof