lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210525220115.GA1233963@bjorn-Precision-5520>
Date:   Tue, 25 May 2021 17:01:15 -0500
From:   Bjorn Helgaas <helgaas@...nel.org>
To:     Amey Narkhede <ameynarkhede03@...il.com>
Cc:     Bjorn Helgaas <bhelgaas@...gle.com>, linux-pci@...r.kernel.org,
        linux-kernel@...r.kernel.org, Leon Romanovsky <leon@...nel.org>
Subject: Re: [PATCH v2] PCI: Check value of resource alignment before using
 __ffs

On Thu, Apr 22, 2021 at 04:25:38PM +0530, Amey Narkhede wrote:
> Return value of __ffs is undefined if no set bit exists in
> its argument. This indicates that the associated BAR has
> invalid alignment.
> 
> Signed-off-by: Amey Narkhede <ameynarkhede03@...il.com>
> ---
>  drivers/pci/setup-bus.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
> index 2ce636937c6e..ce5380bdd2fd 100644
> --- a/drivers/pci/setup-bus.c
> +++ b/drivers/pci/setup-bus.c
> @@ -1044,10 +1044,11 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
>  			 * resources.
>  			 */
>  			align = pci_resource_alignment(dev, r);
> -			order = __ffs(align) - 20;
> -			if (order < 0)
> -				order = 0;
> -			if (order >= ARRAY_SIZE(aligns)) {
> +			if (align) {
> +				order = __ffs(align) - 20;
> +				order = (order < 0) ? 0 : order;
> +			}
> +			if (!align || order >= ARRAY_SIZE(aligns)) {
>  				pci_warn(dev, "disabling BAR %d: %pR (bad alignment %#llx)\n",
>  					 i, r, (unsigned long long) align);
>  				r->flags = 0;

I know this is solving a theoretical problem.  Is it also solving a
*real* problem?

I dislike the way it complicates the code and the usage of "align" and
"order".  I know that when "!align", we don't evaluate the
"order >= ARRAY_SIZE()" (which would involve an uninitialized value),
but it just seems ugly, and I'm not sure how much we benefit.

And the "disabling BAR" part is gross.  I know you're not changing
that part, but it's just wrong.  Setting r->flags = 0 certainly does
not disable the BAR.  It might make Linux ignore it, but that doesn't
mean the hardware ignores it.  When we turn on PCI_COMMAND_MEMORY, the
BAR is enabled along with all the other memory BARs.

Bjorn

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ