All of lore.kernel.org
 help / color / mirror / Atom feed
* [bug report] PCI: Add pci_rebar_size_supported() helper
@ 2025-11-21  9:48 Dan Carpenter
  2025-11-21 11:38 ` Ilpo Järvinen
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2025-11-21  9:48 UTC (permalink / raw)
  To: Ilpo Järvinen; +Cc: linux-pci

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.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-21 11:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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.