cpuid: initialize cpuinfo with boot_cpu_data
authorNorbert Manthey <nmanthey@amazon.de>
Mon, 14 Feb 2022 09:07:36 +0000 (10:07 +0100)
committerJan Beulich <jbeulich@suse.com>
Mon, 14 Feb 2022 09:07:36 +0000 (10:07 +0100)
commit793456d7aa9893d09df55ad2c0986b2a06ea4a98
tree5c848c407676ef9b3c6ede6e3107509bf8817f95
parente6e3cf191d3751a124b108b628183cadbafaa2cb
cpuid: initialize cpuinfo with boot_cpu_data

When re-identifying CPU data, we might use uninitialized data when
checking for the cache line property to adapt the cache
alignment. The data that depends on this uninitialized read is
currently not forwarded.

To avoid problems in the future, initialize the data cpuinfo
structure before re-identifying the CPU again.

The trace to hit the uninitialized read reported by Coverity is:

bool recheck_cpu_features(unsigned int cpu)
...
    struct cpuinfo_x86 c;
    ...
    identify_cpu(&c);

void identify_cpu(struct cpuinfo_x86 *c)
...
    generic_identify(c)

static void generic_identify(struct cpuinfo_x86 *c)
...
        if (this_cpu->c_early_init)
                this_cpu->c_early_init(c); // which is early_init_intel

static void early_init_intel(struct cpuinfo_x86 *c)
...
    if (c->x86 == 15 && c->x86_cache_alignment == 64)
        c->x86_cache_alignment = 128;

This bug was discovered and resolved using Coverity Static Analysis
Security Testing (SAST) by Synopsys, Inc.

Signed-off-by: Norbert Manthey <nmanthey@amazon.de>
Acked-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/cpuid.c