Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devicemodel: hw: pci: gvt: Fix out of bounds error #8118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion devicemodel/hw/pci/gvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,21 @@ gvt_init_config(struct pci_gvt *gvt)
/* capability */
pci_set_cfgdata8(gvt->gvt_pi, PCIR_CAP_PTR, gvt->host_config[0x34]);
cap_ptr = gvt->host_config[0x34];
while (cap_ptr != 0) {
/*
hw/pci/gvt.c:263:41: error: array subscript 257 is above array bounds of ‘uint8_t[256]’ {aka ‘unsigned char[256]’} [-Werror=array-bounds]
263 | gvt->host_config[cap_ptr + 4]);
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
hw/pci/gvt.c:48:17: note: while referencing ‘host_config’
48 | uint8_t host_config[PCI_REGMAX+1];
| ^~~~~~~~~~~

With the additional condition cap_ptr < PCI_REGMAX - 16 it
is ensured that we never read config data from places we
shouln't read from.

12 (offset) + 4 (pci_set_cfgdata32) = 16
*/
while (cap_ptr != 0 && cap_ptr < PCI_REGMAX - 16) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change the pci_set_cfgdata32 to pci_set_cfgdata8. And if the cap_ptr != 0 but exceeds the "PCI_REGMAX - 16" then print some warning logs as some capabilities are lost.

@yakuizhao to comment

pci_set_cfgdata32(gvt->gvt_pi, cap_ptr,
gvt->host_config[cap_ptr]);
pci_set_cfgdata32(gvt->gvt_pi, cap_ptr + 4,
Expand Down