]> xenbits.xensource.com Git - xen.git/commit
x86/hvmloader: fix usage of NULL with cpuid_count()
authorRoger Pau Monne <roger.pau@citrix.com>
Thu, 24 Apr 2025 11:39:45 +0000 (13:39 +0200)
committerRoger Pau Monne <roger.pau@citrix.com>
Fri, 25 Apr 2025 12:50:19 +0000 (14:50 +0200)
commit8f2c5dc611404fe17a1fc7cfc03153c65db2bcd5
tree816baf775a337f7734d7345494333745f59245ad
parentcba90ddee086e8d26063d8de90e40a098395e99b
x86/hvmloader: fix usage of NULL with cpuid_count()

The commit that added support for retrieving the APIC IDs from the APs
introduced several usages of cpuid() with NULL parameters, which is not
handled by the underlying implementation.  For GCC I expect this results in
writes to the physical address at 0, however when using Clang 19.1.2 the
generated code in smp.o for the whole file is:

tools/firmware/hvmloader/smp.o: file format elf32-i386

Disassembly of section .text:

00000000 <smp_initialise>:
       0: 55                            pushl   %ebp
       1: 89 e5                         movl    %esp, %ebp
       3: 53                            pushl   %ebx
       4: 31 c0                         xorl    %eax, %eax
       6: 31 c9                         xorl    %ecx, %ecx
       8: 0f a2                         cpuid

Showing the usage of a NULL pointer results in undefined behavior, and
Clang refusing to generate further code after it.

Fix by using a temporary variable in cpuid_count() in place for any NULL
parameter.

Fixes: 9ad0db58c7e2 ('tools/hvmloader: Retrieve APIC IDs from the APs themselves')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
tools/firmware/hvmloader/util.h