public inbox for linux-pci@vger.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Ziming Du <duziming2@huawei.com>
Cc: bhelgaas@google.com, alex@shazbot.org, chrisw@redhat.com,
	jbarnes@virtuousgeek.org, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org, liuyongqiang13@huawei.com
Subject: Re: [PATCH v4 1/4] PCI/sysfs: Prohibit unaligned access to I/O port
Date: Thu, 26 Feb 2026 11:00:50 -0600	[thread overview]
Message-ID: <20260226170050.GA3812835@bhelgaas> (raw)
In-Reply-To: <20260116081723.1603603-2-duziming2@huawei.com>

On Fri, Jan 16, 2026 at 04:17:18PM +0800, Ziming Du wrote:
> Unaligned access is harmful for non-x86 archs such as arm64. When we
> use pwrite or pread to access the I/O port resources with unaligned
> offset, system will crash as follows:

> @@ -1166,12 +1167,16 @@ static ssize_t pci_resource_io(struct file *filp, struct kobject *kobj,
>  			*(u8 *)buf = inb(port);
>  		return 1;
>  	case 2:
> +		if (!IS_ALIGNED(port, count))
> +			return -EINVAL;

I assume "IS_ALIGNED(port, 1)" is *always* true, so can we just do
this once before the switch instead of adding it to the "case 2" and
"case 4"?

>  		if (write)
>  			outw(*(u16 *)buf, port);
>  		else
>  			*(u16 *)buf = inw(port);
>  		return 2;
>  	case 4:
> +		if (!IS_ALIGNED(port, count))
> +			return -EINVAL;
>  		if (write)
>  			outl(*(u32 *)buf, port);
>  		else
> -- 
> 2.43.0
> 

  reply	other threads:[~2026-02-26 17:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-16  8:17 [PATCH v4 0/4] Miscellaneous fixes for pci subsystem Ziming Du
2026-01-16  8:17 ` [PATCH v4 1/4] PCI/sysfs: Prohibit unaligned access to I/O port Ziming Du
2026-02-26 17:00   ` Bjorn Helgaas [this message]
2026-01-16  8:17 ` [PATCH v4 2/4] PCI/sysfs: Fix null pointer dereference during hotplug Ziming Du
2026-02-26 17:14   ` Bjorn Helgaas
2026-02-27  2:30     ` duziming
2026-04-02  7:23     ` duziming
2026-01-16  8:17 ` [PATCH v4 3/4] PCI: Prevent overflow in proc_bus_pci_write() Ziming Du
2026-03-03 19:32   ` Bjorn Helgaas
2026-01-16  8:17 ` [PATCH v4 4/4] PCI: Prevent overflow in proc_bus_pci_read() Ziming Du
2026-01-30  7:53 ` [PATCH v4 0/4] Miscellaneous fixes for pci subsystem duziming
2026-02-06 22:29   ` Bjorn Helgaas
2026-02-26  9:07     ` duziming

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260226170050.GA3812835@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=alex@shazbot.org \
    --cc=bhelgaas@google.com \
    --cc=chrisw@redhat.com \
    --cc=duziming2@huawei.com \
    --cc=jbarnes@virtuousgeek.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=liuyongqiang13@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox