Re: [PATCH v4] PCI: Check rom header and data structure addr before accessing

From: Guixin Liu

Date: Wed Nov 26 2025 - 20:58:39 EST




在 2025/11/27 01:42, Andy Shevchenko 写道:
On Wed, Nov 26, 2025 at 07:39:18PM +0200, Andy Shevchenko wrote:
On Wed, Nov 26, 2025 at 08:57:27PM +0800, Guixin Liu wrote:
...

image = rom;
do {
void __iomem *pds;
+
+ if (!pci_rom_header_valid(pdev, image, rom, size, true))
break;
+
/* get the PCI data structure and check its "PCIR" signature */
pds = image + readw(image + 24);
+ if (!pci_rom_data_struct_valid(pdev, pds, rom, size))
break;
+
+ last_image = !!(readb(pds + 21) & 0x80);
!!() is not needed.

last_image = readb(pds + 21) & 0x80;
And while at it, isn't this a bit field and

last_image = readb(pds + 21) & BIT(7);

is even more descriptive? Please, check with specification and if it's
a (single) bit, also change this.

Sure, changed in v5.

Best Regards

Guixin Liu
length = readw(pds + 16);
image += length * 512;
+
+ if (!pci_rom_header_valid(pdev, image, rom, size, last_image))
break;
} while (length && !last_image);