From a54ceb1dbe76e76ca8701dbda3e5baf011b16d6d Mon Sep 17 00:00:00 2001 From: Youness Alaoui Date: Wed, 26 Jul 2017 18:03:36 -0400 Subject: rpci: Use pci_dev struct pointer to avoid API breaks The pci_dev structure is never meant to be used as is, but always as a pointer. By using the struct itself in undo_pci_write_data, we are risking data corruption, or buffer overflows if the structure size changes. This is especially apparent on my system where flashrom segfaults because I compile it with pciutils 3.3.0 and I run it on a system with pciutils 3.5.2. The struture size is different and causes a struct with the wrong size to be sent to the library, with invalid internal field values. This has been discovered and discussed in Change ID 18925 [1] [1] https://review.coreboot.org/#/c/18925/ Change-Id: Icde2e587992ba964d4ff92c33aa659850ba06298 Signed-off-by: Youness Alaoui Reviewed-on: https://review.coreboot.org/20784 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber --- programmer.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'programmer.h') diff --git a/programmer.h b/programmer.h index ec00bd9a9..e58fd3257 100644 --- a/programmer.h +++ b/programmer.h @@ -195,6 +195,11 @@ uintptr_t pcidev_readbar(struct pci_dev *dev, int bar); struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar); /* rpci_write_* are reversible writes. The original PCI config space register * contents will be restored on shutdown. + * To clone the pci_dev instances internally, the `pacc` global + * variable has to reference a pci_access method that is compatible + * with the given pci_dev handle. The referenced pci_access (not + * the variable) has to stay valid until the shutdown handlers are + * finished. */ int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data); int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data); -- cgit v1.2.3