Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wei Wang" <wei.w.wang@hotmail.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v7 1/6] PCI: Validate ACS enable flags against device-specific ACS capabilities
Date: Wed, 06 May 2026 20:01:16 +0000	[thread overview]
Message-ID: <20260506200116.E280AC2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <SI2PR01MB43931FC883781B95114B94E1DC3F2@SI2PR01MB4393.apcprd01.prod.exchangelabs.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] The new validation logic unconditionally fails when parsing the `disable_acs_redir` parameter, completely breaking the ability to disable ACS redirection.
- [High] The validation logic incorrectly treats the 'Egress Control Vector Size' field as capability flags, breaking the configuration of Enhanced ACS features and allowing reserved bit corruption.
- [Medium] The complete removal of the `mask` bounds validation allows malformed user strings to clear reserved bits in the ACS Control Register.
--

commit 624557195263e213573cb1ed8cebc0a3dd09d6c8
Author: Wei Wang <wei.w.wang@hotmail.com>

PCI: Validate ACS enable flags against device-specific ACS capabilities

The ACS flag validation is updated to use dev->acs_capabilities instead
of the full set of ACS control bits, ensuring only supported ACS features
are enabled. Note that a regression regarding the disable_acs_redir
parameter was fixed later in the patch series by commit 2b4c7af1c4a60
(PCI: Refactor disable_acs_redir and config_acs param handling).

> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 783e71962cc61..e017200694d8a 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -931,12 +931,6 @@ static void __pci_config_acs(struct pci_dev *dev, struct pci_acs *caps,
>  			}
>  		}
>  
> -		if (mask & ~(PCI_ACS_SV | PCI_ACS_TB | PCI_ACS_RR | PCI_ACS_CR |
> -			    PCI_ACS_UF | PCI_ACS_EC | PCI_ACS_DT)) {
> -			pci_err(dev, "Invalid ACS flags specified\n");
> -			return;
> -		}
> -

Does the removal of the mask validation allow malformed user strings to
clear reserved bits in the ACS Control Register?

If a user specifies 0 in the command line for an upper bit position, that
bit is set in mask but remains clear in flags. Because flags is 0 at that
position, the new validation checks will trivially pass.

The function later evaluates:

caps->ctrl = (caps->fw_ctrl & ~mask) | (flags & mask);

which would unconditionally clear the corresponding bits in the device's ACS
Control register, potentially violating the PCIe specification that dictates
reserved bits must be preserved or read-only.

>  		ret = pci_dev_str_match(dev, p, &p);
>  		if (ret < 0) {
[ ... ]
> @@ -959,6 +953,12 @@ static void __pci_config_acs(struct pci_dev *dev, struct pci_acs *caps,
>  	if (!pci_dev_specific_disable_acs_redir(dev))
>  		return;
>  
> +	if (flags & ~dev->acs_capabilities) {
> +		pci_err(dev, "Invalid ACS enable flags specified: %#06x\n",
> +			(u16)(flags & ~dev->acs_capabilities));
> +		return;
> +	}
> +

Will this validation unconditionally fail when parsing the disable_acs_redir
parameter, breaking the ability to disable ACS redirection?

When the pci=disable_acs_redir parameter is used, __pci_config_acs() is
called with an inverted mask for flags, making acs_flags evaluate to 0xFFD3
as a 16-bit unsigned integer.

Since flags has its upper bits set, and ~dev->acs_capabilities also has its
upper bits set, the bitwise AND will result in a non-zero value. This seems
like it will instantly log an invalid flags error and return early, silently
failing to disable ACS redirection.

Could treating the Egress Control Vector Size field as capability flags break
the configuration of Enhanced ACS features?

dev->acs_capabilities is populated by reading the 16-bit PCI_ACS_CAP register,
where bits 8-15 contain the Egress Control Vector Size integer. Validating
against the full 16-bit value incorrectly uses the vector size as a bitmask
of valid capabilities.

If a user provides a parameter to enable Enhanced ACS controls, the validation
might erroneously reject them unless the device's vector size happens to
have those exact bits set. Conversely, if a device has a non-zero egress
vector size, a user could pass flags corresponding to the set bits in the
vector size, allowing unintended modification of reserved bits in
PCI_ACS_CTRL.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/SI2PR01MB439385689A32A1DDA9CEABE1DC3F2@SI2PR01MB4393.apcprd01.prod.exchangelabs.com?part=1

  reply	other threads:[~2026-05-06 20:01 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-06 14:10 [PATCH v7 0/6] PCI: Add support for ACS Enhanced Capability Wei Wang
2026-05-06 14:10 ` [PATCH v7 1/6] PCI: Validate ACS enable flags against device-specific ACS capabilities Wei Wang
2026-05-06 20:01   ` sashiko-bot [this message]
2026-05-06 14:10 ` [PATCH v7 2/6] Documentation/kernel-parameters: Add multi-device config_acs example Wei Wang
2026-05-06 20:12   ` sashiko-bot
2026-05-06 22:06   ` Randy Dunlap
2026-05-07 13:45     ` Wei Wang
2026-05-06 14:10 ` [PATCH v7 3/6] PCI: Consolidate delimiter handling into pci_dev_str_match() Wei Wang
2026-05-06 16:13   ` Wei Wang
2026-05-06 20:37   ` sashiko-bot
2026-05-06 14:10 ` [PATCH v7 4/6] PCI: Refactor disable_acs_redir and config_acs param handling Wei Wang
2026-05-06 21:07   ` sashiko-bot
2026-05-06 14:10 ` [PATCH v7 5/6] PCI: Enable the enhanced ACS controls introduced by PCI_ACS_ECAP Wei Wang
2026-05-06 21:32   ` sashiko-bot
2026-05-06 14:10 ` [PATCH v7 6/6] PCI: Add the enhanced ACS controls check to pci_acs_flags_enabled() Wei Wang
2026-05-06 21:57   ` sashiko-bot

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=20260506200116.E280AC2BCB0@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko@lists.linux.dev \
    --cc=wei.w.wang@hotmail.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