Michael Jung <mikej at paymentallianceintl.com> reported a kernel panic when fetching VPD date from an Intel X520 10 Gbit/s LAN adapter. The command used was "pciconf -lV" and it can be executed by an unprivileged user.
The cause of this is panic is that bogus VPD data is read from this device, which is not detected as invalid by the current consistency checks in pci_read_vpd().
The panic was caused by an "ident string" of more than 255 bytes (actually 0x6200) whose length was stored into a byte size struct element (vpe_datalen) in pci_list_vpd(). Since elements of more than 255 bytes cannot be copied out (and the standard asks for ident strings of at most 32 bytes), it seems appropriate to reject the VPD data if the length found exceeds 255 bytes.
This review adds further tests that should help detect invalid VPD data. I prefer to delete the bogus data instead of returning them and have therefore made more tests return a state of -2 (and have modified the condition for the checksum check to also reject the VPD if there was no RV record - it is mandatory according to the standard).
I want to offer those stricter checks and return values for review, they are not strictly required, the panic can be prevented by rejecting length > 256 alone. I had added them before the actual cause of the panic was understood. But I think these extra checks and more strict rejection of invalid VPD data gives higher confidence in data that passes all these checks.