-
Notifications
You must be signed in to change notification settings - Fork 524
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
base: master
Are you sure you want to change the base?
devicemodel: hw: pci: gvt: Fix out of bounds error #8118
Conversation
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 shouldn't read from. 12 (offset) + 4 (pci_set_cfgdata32) = 16 I would consider this a workaround that gets the job done for now. However with this approach we can miss the last capabilities in some edge cases. Tracked-On: projectacrn#8116 Signed-off-by: Marius Rodi <[email protected]>
Can one of the admins verify this patch? |
As stated, this fix is more of a workaround. I don't have the time to do this the right way currently. Maybe someone else can have a deeper look into this? |
start to run premerge test |
@ywan170 could you please review this PR? |
|
||
12 (offset) + 4 (pci_set_cfgdata32) = 16 | ||
*/ | ||
while (cap_ptr != 0 && cap_ptr < PCI_REGMAX - 16) { |
There was a problem hiding this comment.
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
With the additional condition
cap_ptr < PCI_REGMAX - 16
it is ensured that we never read config data from places we shouldn't read from.12 (offset) + 4 (pci_set_cfgdata32) = 16
I would consider this a workaround that gets the job done for now. However with this approach we can miss the last capabilities in some edge cases.
Tracked-On: #8116
Signed-off-by: Marius Rodi [email protected]