All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Deepanshu Kartikey" <kartikey406@gmail.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH] PCI: sysfs: Reject unaligned resource I/O port accesses
Date: Sun, 09 Aug 2026 05:16:51 +0000	[thread overview]
Message-ID: <20260809051652.36BA31F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260809045946.15638-1-kartikey406@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The `IS_ALIGNED()` macro is invoked with a user-controlled argument (`count`) that is not guaranteed to be a power of two.
--

--- Patch [1]: [PATCH] PCI: sysfs: Reject unaligned resource I/O port accesses ---
commit 5ca53d551b5755e8c03169b8a70d53f035905df7
Author: Deepanshu Kartikey <kartikey406@gmail.com>

PCI: sysfs: Reject unaligned resource I/O port accesses

This commit adds a check in pci_resource_io() to validate that the requested
port is aligned to the access size. This prevents alignment faults and kernel
oopses on architectures like arm64 when accessing Device-memory mappings.

Closes: https://syzkaller.appspot.com/bug?extid=7134530b25073b4ef373

> diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> index 5ec0b245a69bd..72f0404a34e99 100644
> --- a/drivers/pci/pci-sysfs.c
> +++ b/drivers/pci/pci-sysfs.c
> @@ -1175,6 +1175,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;
> +

[Severity: Low]
Does this code call IS_ALIGNED() with an unvalidated user input for the
alignment argument?

The IS_ALIGNED() macro strictly requires its alignment argument to be a power
of two, but count comes from user space (via pread or pwrite) and could be a
non-power-of-two value like 3. Passing a non-power-of-two value results in
meaningless bitwise operations.

While the subsequent switch (count) statement catches and rejects invalid
sizes by returning -EINVAL, would it be more appropriate to perform this
alignment check after validating that count is actually 1, 2, or 4?

>  	switch (count) {
>  	case 1:
>  		if (write)

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260809045946.15638-1-kartikey406@gmail.com?part=1

  reply	other threads:[~2026-08-09  5:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-09  4:59 [PATCH] PCI: sysfs: Reject unaligned resource I/O port accesses Deepanshu Kartikey
2026-08-09  5:16 ` sashiko-bot [this message]
2026-08-09  7:16 ` Rihyeon Kim
2026-08-21  1:46 ` Deepanshu Kartikey
2026-08-21 16:42   ` Bjorn Helgaas
2026-09-10 11:31 ` Manivannan Sadhasivam
2026-09-23  3:35 ` Deepanshu Kartikey
2026-09-23 20:55   ` Bjorn Helgaas
2026-09-23 21:50     ` David Laight
2026-09-28 12:31       ` Deepanshu Kartikey

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=20260809051652.36BA31F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kartikey406@gmail.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.