Skip to content

Array out of bounds in gvt.c #8116

@ghost

Description

Describe the bug
After following the Getting Started Guide with some adjustments to my needs I get following error. In the make devicemodel part an out of bounds error occurs:

cc -g -O0 -std=gnu11 -D_GNU_SOURCE -DNO_OPENSSL -m64 -Wall -ffunction-sections -Werror -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -fno-strict-aliasing -fno-delete-null-pointer-checks -f
wrapv -fpie -Wno-stringop-truncation -Wno-address-of-packed-member -I/home/mrodi/Linutronix/internal/acrn/acrn-hypervisor/devicemodel/include -I/home/mrodi/Linutronix/internal/acrn/acrn-hypervisor/devicemodel/in
clude/public -I/home/mrodi/Linutronix/internal/acrn/acrn-hypervisor/build/devicemodel/include -I/home/mrodi/Linutronix/internal/acrn/acrn-hypervisor/build/misc/services -I/usr/include/pixman-1 -I/usr/include/gli
b-2.0 -I/usr/include/SDL2 -I/usr/include/EGL -I/usr/include/GLES2 -DIASL_MIN_VER=\"20190703\" -fstack-protector-strong -DDM_DEBUG -c hw/pci/gvt.c -o /home/mrodi/Linutronix/internal/acrn/acrn-hypervisor/build/dev
icemodel/hw/pci/gvt.o -MMD -MT /home/mrodi/Linutronix/internal/acrn/acrn-hypervisor/build/devicemodel/hw/pci/gvt.o
hw/pci/gvt.c: In function ‘gvt_init_config.constprop’:
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];
      |                 ^~~~~~~~~~~
cc1: all warnings being treated as errors
make[1]: *** [Makefile:259: /home/mrodi/Linutronix/internal/acrn/acrn-hypervisor/build/devicemodel/hw/pci/gvt.o] Error 1
make[1]: Leaving directory '/home/mrodi/Linutronix/internal/acrn/acrn-hypervisor/devicemodel'
make: *** [Makefile:136: devicemodel] Error 2

Platform
I am on a Debian Platform using gcc version 12.2.0 (Debian 12.2.0-1).

Codebase
As codebase I use commit 506c87c (HEAD, tag: v3.0).

Scenario
I setup the scenario with two post-launched VMs (Service VM and RT VM).

<?xml version="1.0" encoding="utf-8"?>
<acrn-config>
  <hv>
    <BUILD_TYPE>debug</BUILD_TYPE>
    <FEATURES>
      <IVSHMEM>
        <IVSHMEM_REGION>
          <NAME>Mem1</NAME>
          <PROVIDED_BY>Hypervisor</PROVIDED_BY>
          <IVSHMEM_SIZE>4</IVSHMEM_SIZE>
          <IVSHMEM_VMS>
            <IVSHMEM_VM>
              <VM_NAME>Service_VM</VM_NAME>
              <VBDF>00:08.0</VBDF>
            </IVSHMEM_VM>
            <IVSHMEM_VM>
              <VM_NAME>RT_VM</VM_NAME>
              <VBDF>00:08.0</VBDF>
            </IVSHMEM_VM>
          </IVSHMEM_VMS>
        </IVSHMEM_REGION>
      </IVSHMEM>
      <RELOC_ENABLED>y</RELOC_ENABLED>
      <SCHEDULER>SCHED_PRIO</SCHEDULER>
      <MULTIBOOT2_ENABLED>y</MULTIBOOT2_ENABLED>
      <ENFORCE_TURNOFF_AC>y</ENFORCE_TURNOFF_AC>
      <ENFORCE_TURNOFF_GP>n</ENFORCE_TURNOFF_GP>
      <HYPERV_ENABLED>y</HYPERV_ENABLED>
      <ACPI_PARSE_ENABLED>y</ACPI_PARSE_ENABLED>
      <L1D_VMENTRY_ENABLED>n</L1D_VMENTRY_ENABLED>
      <MCE_ON_PSC_DISABLED>n</MCE_ON_PSC_DISABLED>
      <SSRAM>
        <SSRAM_ENABLED>n</SSRAM_ENABLED>
      </SSRAM>
      <RDT>
        <RDT_ENABLED>n</RDT_ENABLED>
        <CDP_ENABLED>n</CDP_ENABLED>
        <VCAT_ENABLED>n</VCAT_ENABLED>
      </RDT>
      <SECURITY_VM_FIXUP>n</SECURITY_VM_FIXUP>
      <KEEP_IRQ_DISABLED>n</KEEP_IRQ_DISABLED>
      <IOMMU_ENFORCE_SNP>n</IOMMU_ENFORCE_SNP>
    </FEATURES>
    <DEBUG_OPTIONS>
      <SERIAL_CONSOLE>/dev/ttyS4</SERIAL_CONSOLE>
      <MEM_LOGLEVEL>5</MEM_LOGLEVEL>
      <NPK_LOGLEVEL>5</NPK_LOGLEVEL>
      <CONSOLE_LOGLEVEL>5</CONSOLE_LOGLEVEL>
    </DEBUG_OPTIONS>
    <MEMORY>
      <STACK_SIZE>0x2000</STACK_SIZE>
    </MEMORY>
    <CAPACITIES>
      <MAX_PCI_DEV_NUM>96</MAX_PCI_DEV_NUM>
      <MAX_PT_IRQ_ENTRIES>256</MAX_PT_IRQ_ENTRIES>
      <MAX_MSIX_TABLE_NUM>64</MAX_MSIX_TABLE_NUM>
      <MAX_EMULATED_MMIO>16</MAX_EMULATED_MMIO>
      <MAX_VM_NUM>16</MAX_VM_NUM>
      <MAX_IOAPIC_NUM>1</MAX_IOAPIC_NUM>
      <MAX_IOAPIC_LINES>120</MAX_IOAPIC_LINES>
    </CAPACITIES>
    <MISC_CFG>
      <GPU_SBDF>0x00000010</GPU_SBDF>
    </MISC_CFG>
  </hv>
  <vm id="0">
    <vm_type>STANDARD_VM</vm_type>
    <console_vuart>None</console_vuart>
    <os_config>
      <kern_type>KERNEL_BZIMAGE</kern_type>
      <kern_mod>Linux_bzImage</kern_mod>
      <bootargs>rw rootwait root=/dev/nvme0n1p2 console=tty0 console=ttyS0 consoleblank=0 no_timer_check quiet loglevel=3 i915.nuclear_pageflip=1 swiotlb=131072</bootargs>
    </os_config>
    <load_order>SERVICE_VM</load_order>
    <name>Service_VM</name>
    <priority>PRIO_LOW</priority>
    <companion_vmid>65535</companion_vmid>
  </vm>
  <vm id="1">
    <vm_type>RTVM</vm_type>
    <console_vuart>None</console_vuart>
    <os_type>Non-Windows OS</os_type>
    <vuart0>n</vuart0>
    <vbootloader>y</vbootloader>
    <memory>
      <size>1024</size>
    </memory>
    <cpu_affinity>
      <pcpu>
        <pcpu_id>2</pcpu_id>
        <real_time_vcpu>n</real_time_vcpu>
      </pcpu>
    </cpu_affinity>
    <virtio_devices>
      <console>
        <use_type>Virtio console</use_type>
        <backend_type>stdio</backend_type>
      </console>
      <block>/home/mrodi/Linutronix/internal/acrn/acrn-work/ubuntu-22.04.1-desktop-amd64.iso</block>
    </virtio_devices>
    <load_order>POST_LAUNCHED_VM</load_order>
    <name>RT_VM</name>
    <priority>PRIO_LOW</priority>
    <companion_vmid>65535</companion_vmid>
  </vm>
</acrn-config>

To Reproduce
make clean && make all BOARD=myboard.xml SCENARIO=myscenario.xml on a System with gcc version 12.2.0 (Debian 12.2.0-1).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions