mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 09:36:22 +02:00
alpha/PCI: Fix __pci_mmap_fits() overflow for zero-length BARs
Currently, __pci_mmap_fits() computes the BAR size using
"pci_resource_len() - 1", which wraps to a large value when the BAR length
is zero, causing the bounds check to incorrectly succeed.
Add an early return for empty resources.
Fixes: 10a0ef39fb ("PCI/alpha: pci sysfs resources")
Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Tested-by: Magnus Lindholm <linmag7@gmail.com>
Tested-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Acked-by: Magnus Lindholm <linmag7@gmail.com>
Link: https://patch.msgid.link/20260508043543.217179-15-kwilczynski@kernel.org
This commit is contained in:
parent
30d01a8c3a
commit
802a3b3f47
|
|
@ -37,12 +37,16 @@ static int hose_mmap_page_range(struct pci_controller *hose,
|
|||
static int __pci_mmap_fits(struct pci_dev *pdev, int num,
|
||||
struct vm_area_struct *vma, int sparse)
|
||||
{
|
||||
resource_size_t len = pci_resource_len(pdev, num);
|
||||
unsigned long nr, start, size;
|
||||
int shift = sparse ? 5 : 0;
|
||||
|
||||
if (!len)
|
||||
return 0;
|
||||
|
||||
nr = vma_pages(vma);
|
||||
start = vma->vm_pgoff;
|
||||
size = ((pci_resource_len(pdev, num) - 1) >> (PAGE_SHIFT - shift)) + 1;
|
||||
size = ((len - 1) >> (PAGE_SHIFT - shift)) + 1;
|
||||
|
||||
if (start < size && size - start >= nr)
|
||||
return 1;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user