All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: linux-pci@vger.kernel.org
Subject: Re: [bug report] PCI: Add pci_rebar_size_supported() helper
Date: Fri, 21 Nov 2025 13:38:01 +0200 (EET)	[thread overview]
Message-ID: <a2e52d2e-fe9e-6f55-454a-4e7710c2c1ca@linux.intel.com> (raw)
In-Reply-To: <aSA1WiRG3RuhqZMY@stanley.mountain>

[-- Attachment #1: Type: text/plain, Size: 1660 bytes --]

On Fri, 21 Nov 2025, Dan Carpenter wrote:

> Hello Ilpo Järvinen,
> 
> Commit bb1fabd0d94e ("PCI: Add pci_rebar_size_supported() helper")
> from Nov 13, 2025 (linux-next), leads to the following Smatch static
> checker warning:
> 
> 	drivers/pci/rebar.c:142 pci_rebar_size_supported()
> 	error: undefined (user controlled) shift '(((1))) << size'
> 
> The problem is this call tree:
> __resource_resize_store() <- takes an unsigned long from the user
>   -> pci_resize_resource() <- truncates it to int
>      -> pci_rebar_size_supported()
> 
> drivers/pci/rebar.c
>     138 bool pci_rebar_size_supported(struct pci_dev *pdev, int bar, int size)
>     139 {
>     140         u64 sizes = pci_rebar_get_possible_sizes(pdev, bar);
>     141 
> --> 142         return BIT(size) & sizes;
>     143 }
> 
> So here size could be negative or >= BITS_PER_LONG which leads to
> shift wrapping.  But also truncating the ulong to int in
> __resource_resize_store() is not beautiful.

Thanks Dan!

I've not liked using int for those size parameters as the field on PCIe 
side is obviously unsigned (less than u8 actually, PCIe r7.0, sec 7.8.6.3) 
but haven't yet spent time on converting them either.

The issue seems older though than introduction of 
pci_rebar_size_supported() in the commit bb1fabd0d94e ("PCI: Add 
pci_rebar_size_supported() helper") that just moved that BIT() inside the 
newly introduced function.

I'll send the fix next week (I wrote it already but they seem to be doing 
some electric work over this weekend so I can't easily do testing for it 
with systems I normally play with BAR resizing).

-- 
 i.

      reply	other threads:[~2025-11-21 11:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-21  9:48 [bug report] PCI: Add pci_rebar_size_supported() helper Dan Carpenter
2025-11-21 11:38 ` Ilpo Järvinen [this message]

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=a2e52d2e-fe9e-6f55-454a-4e7710c2c1ca@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=dan.carpenter@linaro.org \
    --cc=linux-pci@vger.kernel.org \
    /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.