From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: shao.mingyin@zte.com.cn
Cc: bhelgaas@google.com, linux-pci@vger.kernel.org, mani@kernel.org,
kwilczynski@kernel.org, lpieralisi@kernel.org,
kishon@kernel.org, Frank.Li@kernel.org,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/5] PCI: Reject negative resource alignment order
Date: Fri, 6 Nov 2026 18:39:45 +0200 (EET) [thread overview]
Message-ID: <89d84d22-9c75-c49b-a4f7-4682a80187d7@linux.intel.com> (raw)
In-Reply-To: <20261107002311316z2o2PFtFGoXh-VbqXtTGg@zte.com.cn>
On Sat, 7 Nov 2026, shao.mingyin@zte.com.cn wrote:
> From: Shao Mingyin <shao.mingyin@zte.com.cn>
>
> pci_specified_resource_alignment() parses the pci=resource_alignment=
> boot parameter with sscanf("%d%n", &align_order, ...) and rejects only
> orders above 63. A negative order, e.g. "pci=resource_alignment=-5@...",
> passes that check and later reaches "align = 1ULL << align_order" with a
> negative shift count, which is undefined behavior; on x86 the 64-bit
> shift count is masked to six bits, silently producing a 2^59-byte
> alignment that mis-aligns (or fails to align) the affected IOV resources.
>
> Reject any order outside the valid [0, 63] range and fall back to the
> default page-size alignment, matching the existing handling of
> out-of-range positive orders.
>
> Fixes: 6534aac198b5 ("PCI: Bounds-check command-line resource alignment requests")
> Cc: stable@vger.kernel.org
> Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
> ---
> Tested on 7.3.0-next-20261030 (QEMU/TCG guest) with the
> pci=resource_alignment= boot parameter and a QEMU e1000 NIC; no extra
> hardware is needed.
>
> Booting with pci=resource_alignment=-5@pci:8086:100e parses a negative
> order that the "> 63" check lets through, so "align = 1ULL << align_order"
> shifts by -5 (masked to 2^59 on x86-64); the e1000 BAR is resized to
> 2^59 bytes, which cannot be assigned, and the e1000 fails to probe:
>
> unpatched patched
> requesting alignment to PCI: Invalid requested alignment
> 0x800000000000000 (order -5)
> e1000 probe failed, no eth0 e1000 eth0 probes
>
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index bca3a5d84cd9..c2260ee1f956 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -6605,7 +6605,7 @@ static resource_size_t pci_specified_resource_alignment(struct pci_dev *dev,
> if (sscanf(p, "%d%n", &align_order, &count) == 1 &&
> p[count] == '@') {
> p += count + 1;
> - if (align_order > 63) {
> + if (align_order < 0 || align_order > 63) {
Wouldn't it be better to use %u ?
> pr_err("PCI: Invalid requested alignment (order %d)\n",
> align_order);
> align_order = PAGE_SHIFT;
>
--
i.
next prev parent reply other threads:[~2026-11-06 16:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 16:23 [PATCH 0/5] PCI: Fix invalid input handling and a NULL dereference shao.mingyin
2026-11-06 16:23 ` [PATCH 1/5] PCI: Reject negative resource alignment order shao.mingyin
2026-11-06 16:39 ` Ilpo Järvinen [this message]
2026-11-06 17:13 ` shao.mingyin
2026-11-06 16:23 ` [PATCH 2/5] PCI: of: Bound num_lanes in of_pci_get_equalization_presets() shao.mingyin
2026-11-06 16:23 ` [PATCH 3/5] PCI/ASPM: Skip link-state setup without downstream function 0 shao.mingyin
2026-11-06 16:23 ` [PATCH 4/5] PCI: rebar: Guard pci_rebar_bytes_to_size() against overflow shao.mingyin
2026-11-06 16:37 ` Ilpo Järvinen
2026-11-06 17:11 ` shao.mingyin
2026-11-06 16:23 ` [PATCH 5/5] PCI: endpoint: Reject a zero interrupt number in raise_irq shao.mingyin
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=89d84d22-9c75-c49b-a4f7-4682a80187d7@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=Frank.Li@kernel.org \
--cc=bhelgaas@google.com \
--cc=kishon@kernel.org \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
--cc=shao.mingyin@zte.com.cn \
/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.