[3/4] bus/pci/bsd: Eliminate potential overflow
Checks
Commit Message
When calling rte_pci_write_config(), use memcpy(3) to copy @len bytes
of @buf into local memory instead of casting it to a uint32_t pointer
and dereferencing it. This prevents us from reading data outside of
@buf in the case that @buf has a length less than 32 bits.
Signed-off-by: Jake Freeland <jfree@FreeBSD.org>
---
drivers/bus/pci/bsd/pci.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
Comments
On 5/6/2025 7:40 PM, Jake Freeland wrote:
> When calling rte_pci_write_config(), use memcpy(3) to copy @len bytes
> of @buf into local memory instead of casting it to a uint32_t pointer
> and dereferencing it. This prevents us from reading data outside of
> @buf in the case that @buf has a length less than 32 bits.
>
> Signed-off-by: Jake Freeland <jfree@FreeBSD.org>
> ---
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
@@ -467,7 +467,6 @@ int rte_pci_write_config(const struct rte_pci_device *dev,
.pc_func = dev->addr.function,
},
.pi_reg = offset,
- .pi_data = *(const uint32_t *)buf,
.pi_width = len,
};
@@ -476,7 +475,7 @@ int rte_pci_write_config(const struct rte_pci_device *dev,
goto error;
}
- memcpy(&pi.pi_data, buf, len);
+ memcpy(&pi.pi_data, buf, MIN(len, sizeof(pi.pi_data)));
fd = open("/dev/pci", O_RDWR);
if (fd < 0) {